If I use "assigned" ids, saveOrUpdate, and cascaded collections appear to not function with unsaved objects that have their unique ids already assigned. In this sense "assigned" ids appear to be second class citizens.
I have an application where I need to be able to send my records from 1 database to another (a sort of home-brewed replication), keeping the same unique id. I basically open a hibernate session to the source database, and one to the destination database, and I use the same mapping, only the db connection differs. Then I basically query the objects I want from the source database, and then save them to the destination. If I use a generated id, like uuid.hex, that works for inserting the record in the source, but when i want to add an existing record from the src, to the dest, with the same id, using the same mapping, it won't work because the id is not null.
Now, if I change my ids to be assigned, this seems to work in some cases, if i avoid saveOrUpdate, and avoid putting these objects in collections that are cascaded from their owner. but i need these features.
I'm not complaining about the behaviour of "assigned" unique ids, although I think their status could be better documented in the manual. I'm really just looking for advice as to how to create a single mapping that allows the same objects to exist in 2 different databases, with an easy way to match up an object with its twin.
|