0

I need to read object tree using hibernate from a database on a machine(Source) and persist it to another database on an other machine(Destination). Objects i read from source machine have their IDs and when persisting to destination machine, they overwrite objects with same IDs.

How can i persist a complete object tree without having to manually and recursively erase all IDs ?

Emil Laine
  • 41,598
  • 9
  • 101
  • 157
Mak
  • 35
  • 6
  • So if the destination database already contains different data (so you overwrite them) you obviously cannot use the ids from original data and you have to refresh them. – Zielu Feb 26 '15 at 01:44
  • see [hibernate copy object values into new object](http://stackoverflow.com/questions/9944882/hibernate-copy-object-values-into-new-object-with-new-generated-id) - essentially detach and reset ids to null – harshtuna Feb 26 '15 at 02:03
  • a bit off topic: I don't see the reason of using Hibernate in such cases. Are there any reason that you choose to implement this kind of replication feature with Hibernate? It is probably not what Hibernate is good at – Adrian Shum May 04 '16 at 06:27
  • I have used hibernate as ORM persistence framework. However , I have another use case where in I could export the data from a source database to a destination database. To address this use case, I retrieve the object tree marshall to xml . Later un-marshall and import into new destination database. – Mak May 04 '16 at 06:34
  • @Mak That's what I mean it is not suitable: Why do you need to use an ORM layer for such purpose? Simply export the data as DDL, and import it in the destination server is going to be faster, safer and less error-prone – Adrian Shum May 04 '16 at 09:17

1 Answers1

0

I solved this issue by marshaling the object tree into xml and un-marshalling back into java object tree. In the un-marshaling configuration, I white washed all the ID'S.

Mak
  • 35
  • 6