-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Cascade and Identifier Key problem
PostPosted: Wed Jan 19, 2005 12:16 am 
Beginner
Beginner

Joined: Thu Dec 04, 2003 3:47 am
Posts: 31
Location: Hong Kong
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.