not sure if this is by design or if it is a bug, but i'm 90% sure that this is what is going on. i have two transient objects in memory: A and B, each of which has a one-to-many relationship with a lazy loading collection C (which has been initialized on both instances). the same instance of the class in C is associated to both A and B. now, when i do:
session.lock(A, LockMode.NONE);
i see a bunch of:
Code:
11:52:55,388 DEBUG Cascades:326 - processing cascades for: com.sa.go.bto.Business
11:52:55,398 DEBUG Cascades:350 - cascading to collection: com.sa.go.bto.Business.categories
11:52:55,398 DEBUG Cascades:72 - cascading to lock()
11:52:55,398 DEBUG Cascades:259 - unsaved-value strategy NULL
11:52:55,398 DEBUG SessionImpl:1605 - reassociating transient instance: [com.sa.go.bto.Category#71]
11:52:55,398 DEBUG Cascades:72 - cascading to lock()
you can see that the transient instances in collection C are be cascaded to lock() as well - which is fine. problem is, i now do:
session.lock(B, LockMode.NONE);
and then issue a session.flush(), i get:
Code:
net.sf.hibernate.HibernateException: Another object was associated with this id (the object with the given id was already loaded): [com.sa.go.bto.Category#115]
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1301)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1232)
at net.sf.hibernate.engine.Cascades$5.cascade(Cascades.java:105)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:280)
....
is this a bug in the cascading code for lock() calls?