Hello
I am using Hibernate 3.0 and I have a problem duplicating (deep cloning) an object. Suppose me having Something object that contains OtherThing object. Both objects are stored in separate tables and OtherThing is mapped to Something with cascade="all".
Code:
Something something = (Something) session.load(Something.class, somethingId);
session.evict(something);
something.setId(null);
OtherThing ot = something.getOtherThing();
od.setId(null);
session.save(something);
This code throws an exception:
Code:
AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: null identifier
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:33)
at org.hibernate.engine.PersistenceContext.reassociateProxy(PersistenceContext.java:489)
at org.hibernate.engine.PersistenceContext.unproxyAndReassociate(PersistenceContext.java:528)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:65)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:429)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:424)
Please tell me how to clone object with all its children most effeciently (I don't wanna use object.clone() if possible). My real classes contains not only single objects but collections as well (one-to-many mappings ...).
Thanks a lot
Martin