Hi,
I am using Hibernate 3.2.2 ga.
I've been struggling to get some work done in an event listener (specifically the pre-update event listener, but I think the problem is more general). I want to be able to make some db changes (i.e. update a few existing entities and add some new ones) within the event listener. Everything I've tried seems to end up in different types of exceptions getting thrown , for e.g.:
Code:
org.hibernate.AssertionFailure: collection [XXXXX] was not processed by flush()
at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:205)
at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:333)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)
....
I'd be happy to be proved wrong, but I'm getting the increasingly frustrating feeling that the event listeners do not support re-entrant session method calls (i.e., flush/persist/update etc) and that in order to get a listener to update the database you need a separate new session for it.
This is a shame as I would like my listener to be able to make the changes within the same JTA transaction that was used for the normal operations that took place before the listener got fired so that the listener's work gets committed/rolledback synchronously with the rest of the operations.
Nothing in the documentation seems to indicate that listeners can't reuse the existing session.
If this is not possible, is there any other way I can accomplish what I want to do?
Thanks,
Ishaaq
Code: