Well, just tried that.
But despite the apidoc which says...
Persist the state of the given detached instance,
reusing the current identifier value. This operation cascades to associated instances if the association is mapped with cascade="replicate".
...a new one is generated. :-((((
I debugged replicate() and found that in the end it uses the prepared insert-statement that leaves out the id-column, hence a new value is generated (in our case by an autoincrement field of MySQL5). But at least in MySQL you can set the value of an autoincrement field if it is given in the insert statement.
This is somehow related to
http://forum.hibernate.org/viewtopic.php?t=948071
I want to import my xml-backup'd data in a fashion that is contrain-friendly. I.e. objects are inserted back in an order where new objects only reference objects that are already there. Plus I don't care for replication-cascading. I only want the ids of my main objects preserved as they act as keys to the outside that mustn't change after first use. Internal ids for embedded relations may change freely.
So I have to go back to the other idea to "solve" this...add another column to each relevant entity class with an external id that is initialized by the value of the auto generated id and then stays untouched on each backup/restore.
But thanks for trying to help anyway!
Much appreciated.