Hibernate 2.1.8, Spring 1.2.6.
In my webapp I have a Parent object which contains a Children collection which I've just switched to 'lazy=true'. I need to store the Parent object in the HTTP session, do something with a Child (in another request) and then retrieve the Parent object from the HTTP session and update the Children collection with the new version of the Child. After switching to 'lazy=true', I was getting LazyInitializationExceptions when trying to use the collection in the Parent reloaded from the HTTP session. I got around this by calling Session.lock() on the Parent object when I retrieved it from the HTTP session, to reassociate it with the Hibernate session. Now, however, when I try to save the Parent record I get the following:
Code:
net.sf.hibernate.HibernateException: reassociated object has dirty collection reference
at net.sf.hibernate.impl.OnLockVisitor.processCollection(OnLockVisitor.java:53)
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:91)
at net.sf.hibernate.impl.SessionImpl.reassociate(SessionImpl.java:1699)
at net.sf.hibernate.impl.SessionImpl.lock(SessionImpl.java:1719)
What do I need to do to be able to:
a) In one request, store a parent object with a one-to-many lazy loaded collection in a session.
b) Retrieve this in a second request, update some children.
c) Retrieve the parent object again for further editing in a third request
Alternatively, what am I neglecting to do in the second request which is causing the 'dirty collection reference' problem?