Originally posted by Antero Laukkanen:
I have this complex object graph I need to be able to persist and more problematically, copy it once it has been persisted so that I can insert the copy also so that changes to it are not visible to the original graph. How to?
Using SerializationHelper in org.hibernate.utils I can create a deep-copy of the object graph except I think the lazily loaded properties are not initialized (?). Supposing I could get the full copy, however, the id's would still be the same as for the originals. To insert the object again, would setting the id's to default values be enough or will there be issues because the object is the proxy?
All in all, am I going the totally wrong way with this?
Hi Antero,
Not sure exactly what you are trying to do, but
you should not use vendor-specific or Hibernate-specific API if you can avoid it, and in this case you can. Simply use the merge() method, which returns managed copies of the objects that you want to persist. The original objects are not managed, hence you can change them and merge them in later if you want.