I have already described this problem in a reply to another topic [NullPointerException in SessionImpl.getOrphans()], but nobody seems to look at it. So here it is again ;-)
In the other topic, Gavin asked me to put a line of code into Hibernate 2.1.2 in order to fix another issue:
Quote:
Add the following line to SessionImpl.doUpdateMutable():
Code:
if ( ( (Lifecycle) object ).onUpdate(this) ) { // do callback
log.debug("update vetoed by onUpdate()");
reassociate(object, id, persister); //<---- New Line!
return;
}
The new line of code fixed my problem, but I believe it might be be responsible for another problem I now have in the constellation decribed below. I believe this because the new line of code appears in the stack trace.
Class A has a one-to-many collection of class B with cascade="all-delete-orphan", inverse="true". Class B has a many-to-one reference to class C, which in turn has a one-to-many collection of class B with cascade="all-delete-orphan", inverse="true".
The entire object graph consists of detached objects. I want to remove an instance of B by removing if from the collections in A and C. When I call saveOrUpdate(), the instance of C vetoes the update for application-specific reasons. This causes the operation to fail with
HibernateException: reassociated object has dirty collection (details below)
I do understand the general reason why this exception would be thrown, but I am not sure that it is appropriate in this case for several reasons:
1. The table containing C doesn't need to be updated, so no problem.
2. The collection has inverse="true", so it is not C's job to maintain it.
3. This was not a problem in 2.1 final (not sure that counts).
net.sf.hibernate.HibernateException: reassociated object has dirty collection
at net.sf.hibernate.impl.OnLockVisitor.processCollection(OnLockVisitor.java:47)
at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
at net.sf.hibernate.impl.AbstractVisitor.processValues(AbstractVisitor.java:36)
at net.sf.hibernate.impl.AbstractVisitor.process(AbstractVisitor.java:93)
at net.sf.hibernate.impl.SessionImpl.reassociate(SessionImpl.java:1654)
at net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1420)
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1441)
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:1446)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1364)