Hibernate 2.1b]
I have a parent class P, with children class C. Children class also has sub children class D. There are two children instances c1, c2. Each of c1, c2 would have 8 sub children instances d1, d2..., d8. All instances are with identifier key (auto generated from mysql auto-increasement key column) P to C is one-to-many mapping with "delete-all-orphan" cascade. C to D is one-to-many mapping with "delete-all-orphan" cascade.
After I constructed all the classes and assigned the relationship, I persist parent instance p of class P, which will then propagated to all chidren instances c1, c2 and sub children instances d1, d2 ... but then an exception thrown stating that object in class D with the same identifier value is associated with the same session.
so my understanding is that, before instances of class D being persisted, all of them have the same identifier value (say 0 as java default value of int) If they are persisted one by one, they would be generated with unique identifier value. However, when they are persisted through the cascade effect, I'm not sure how the behavour would be. So it is resulted in the following exception. Anyone has any idea can help?
[b]Caused by: net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 0, of class: D at net.sf.hibernate.impl.SessionImpl.checkUniqueness(SessionImpl.java:1642) at net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1414) at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1440) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1364) at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436) at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482) at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1445) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1364) at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436) at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482) at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2639) at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2214) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2203) at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61) at org.astri.inos.pes.service.TransactionalCommand.execute(TransactionalCommand.java:26) at org.astri.inos.pes.service.ServiceLocatorImpl$ManagerDelegate.invoke(ServiceLocatorImpl.java:88) ... 15 more
MySQL 4.0.12
|