I am happy with this behavior, it gives consistent semantics for lock(), and exhibits the reasonable
behavior that a vetoed update() results in a lock().
In general, Lifecycle is no longer something we really recommend and we are creating a whole new
event API in Hibernate3.
It should be straightforward to find some other way to solve your problem, I suppose. (eg. just
don't dirty your collection.)
Mao, Dean (IHG) wrote:
I'm asking this question on the mailing list since nobody has replied to the hibernate forum posting for several weeks. This was posted by another developer on our team. It has been viewed 60 times but no informative posts to it yet. This is the link to the original posting:
http://forum.hibernate.org/viewtopic.php?t=928340
This is fljmayer's posting: ------------------------
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:
Add the following line to SessionImpl.doUpdateMutable():
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)
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel
-- Gavin King +61 410534454
Hibernate [EMAIL PROTECTED] http://hibernate.org
JBoss Inc [EMAIL PROTECTED] http://jboss.com
------------------------------------------------------- This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek For a limited time only, get FREE Ground shipping on all orders of $35 or more. Hurry up and shop folks, this offer expires April 30th! http://www.thinkgeek.com/freeshipping/?cpg=12297 _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel