Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.1 release candidate 3
Hi,
Whenever an object of a particular class is updated, I need to update a property on each member of one of its collection properties as well.
I'm trying to implement this using Hibernate events. I've tried pre & post update events, and nothing seems to let me do this.
In particular, in onPreUpdate(), if I try to iterate through any collection properties on the event entity, it bombs after trying to do the update.
This is ok:
Code:
entity.getCollectionA();
This results in an error after the actual update is attempted by Hibernate (not immediately):
Code:
entity.getCollectionA().iterator();
Code:
org.hibernate.AssertionFailure: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: collection was not processed by flush()
at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:183)
at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:328)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:908)
The above error only happens if the collection is lazy. If it is not lazy, then I don't get any errors, but none of my modifcations to the property values are persisted.
Based on my reading from the docs and forum, it looks like this may be a session management issue. I'm using the Threadlocal method from the HibernateUtil example. I've also tried creating a temporary session as per the example in Hibernate In Action.
I've seen a few simarly questions on this in the forums, but no real answers.
Can anyone some idea on where to start looking for a solution?
Thank you