开发者

Synchronization between hibernate running locally and on a server

Is there an easy way using a library to facilitate the synchronization of two hibernate instances. One running locally on a client and one running on a central server exposed via a web service.

So Client tracks changes it makes, pushes them to the Server. The server ensures that the clients is not updating out of sync objects and stores the clients changes.

The Client can also sync with the Server so that it can see the changes made by other clients.

The idea is that the client can be run offline, without access to the开发者_高级运维 server and only come online to synchronize when needed.


There is no 'magical' way of achieving it. You have to do something like this:

  • make a version or lastModified field for each entity
  • send (via web-services, rmi, or whatever is at your disposal) the local hibernate entities in a serialized form (object seriralization, xml, json)
  • the new entities first - just persist them on the server
  • deleted entities second - you'll have to store somewhere their ids and version. If the version on the server hasn't been changed, delete them. If it has - decide for yourself whether to delete them or not
  • updated entities third - again compare the version field. If there has been no modification on the server, persist the new entity. If there has been modification, there are a few options:
    • report merge conflict and don't merge them
    • override the server version with the one from the client
    • implement a more complex merge mechanism, where each field has its own version, but that's far too complex


I'm not sure to get everything but clients that can be temporarily disconnected are not an easy thing to deal with. Such clients will typically need an embedded database which means synchronization and/or merge with the master database when back online and this is really far from being a trivial process. So, to answer your initial question, I'm aftraid there is no easy way to achieve this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜