Hibernate version:2.1.6
I have a 'master' database server and a list of 'remote' databases.
There is a set of tables that get maintained on the master that I will periodically push out deltas to the remote sites. For the remote sites these tables are reference data, they don't get modified at the remote sites except to use the deltas to synchonize with the master.
An example of this scheme would be a 'price list' that gets maintained at the corporate center and gets pushed out to all the branches on a weekly basis.
My question concerns how to deal with identifiers at the remote sites.
Let me explain a little more.
On the master I'm using synthetic keys with native generator, and a version property. This is all new design from scratch so I'm trying to follow hibernate best practices.
On a sychronize operation, I send a list of deltas (added, updated, deleted objects) to the remote server via an http transaction. At the remote site I reconsitute the objects and use them to update the tables.
So the question is: what do I do for identifiers on the remote sites?
1) Do I use the same identifier from the master but make it "assigned"?
2) Do I give them a separate generated id and just store the master-id in a another property to use for matching records for updates and deletes?
3) Is there a hibernate design pattern for this situation?
My first thought was 1) to use the master id but make it "assigned"; but this was immediately a problem with inserts because there was nothing in the object to use as an 'unsaved-value'. And some of the objects have parent/child one-to-many sets; I was having to individually save/flush the parent and each child object.
So I decided to try 2) and give the remote table there own generated identifiers and store the master-id in a separate property.
This works fine for the inserts and the deletes but the updates are a pain.
To update the list of objects I have to one-by-one get it from the database by the master-id value then update all the property fields.
Is there a better way to do this?
What I would like to be able to do is this: After I reconstitute the object from the http transaction just tell hibernate "Here is what the object should look like"... "make it so!".
Is there a hibernate design pattern for this situation?
What would the experts do?
|