Dear Hibernate forum,
I'm implementing import/export functionality in our project that is using
Hibernate as a data persistence layer. I would like to import objects
previously exported to XML back to the database
preserving their original ids.
Objects are deserialized from XML using XStream (
http://xstream.codehaus.org)
with some customizations (deserialization also restores original id to the transient object).
After deserialization I would like to save the transient object to the database ideally
using something similar to
Session.replicate() (ReplicationMode gives perfect sense
in this case and I would probably let the user choose which kind of import
is preferable).
The problem is that
Session.replicate(object, replicationMode) requires
the
object to be
detached instance for some reason.
I was thinking about trying to "fake" Hibernate to accept transient
instances received from deserialization as detached instances in
replicate(), but this seems a bit unsafe (How exactly does Hibernate
distinguish between detached and transient instance?).
Another idea was to use 'assigned' ids instead of id-generator, but I would
consider this as a "last-resort" solution.
Do you have any suggestions how to accomplish such import that would preserve original ids?
Any comments would be highly appreciated.
Best Regards!
--
Pavol Juhos