[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2763) (lazy) m:n relation + EventListener = AssertionFailure: collection [n-side] was not processed by flush()
benoit heinrich (JIRA)
noreply at atlassian.com
Thu Jun 24 16:12:13 EDT 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2763?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=37575#action_37575 ]
benoit heinrich commented on HHH-2763:
--------------------------------------
Hi all,
I know this problem is there now for a very long time, but today has been my turn to play with it, and after struggling a long day on it, I went to a solution that seems quiet generic and work very well for me.
The idea is that when you use an hibernate event, if you try accessing a lazy collection, then the CollectionEntry corresponding to the lazily loaded collection get added to the PersistenceContext and hibernate crashes when it finds those entries because they are neither processed, neither ignored.
After thinking a bit of the problem, and reading a lot in the different bug reports, I came to a conclusion that if the entries are not yet processed (because really, they're not) then maybe we could process them later on, after the flush() is done.
Still, on the same idea, I looked deep in the hibernate code, and I've created a new FlushEventListener that replace the default one (EJB3FlushEventListener because I'm running in a jboss app server) and I'm simply removing the CollectionEntry that are considered invalid from the PersistenceContext during the postFlush(), and then, once the postFlush() is done, I'm adding these entries again into the PersistenceContext and I'm flushing again.
The way this automatic "flush() again" is implemented allows the user to have multiple events generated by other events as much as you want (that's a lie, there is a limit of 100 right now) and it'll automatically "flush() again" every time it's needed, and this is all transparent to the code.
I've attached the class, so if you want to try it feel free to use it.
If you have any comment concerning the way I've implemented that workaround, then feel free to either send me an email, or reply to this bug, and make sure that you vote for it, so one day we get it fixed properly by the hibernate team ;)
Cheers,
/Benoit
> (lazy) m:n relation + EventListener = AssertionFailure: collection [n-side] was not processed by flush()
> --------------------------------------------------------------------------------------------------------
>
> Key: HHH-2763
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2763
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.2.4.sp1, 3.2.5
> Environment: Windows-XP, Jboss 4.2.1GA, Hibernate 3.2.4SP1, EJB3
> Reporter: S.Schnabl
> Assignee: Steve Ebersole
> Priority: Critical
> Attachments: bidirectional_many-to-many.gif, cdel_analyse.txt, HHH-2763_standalone_testcases.zip, one-to-many_with_many_side_having_collections.gif, Testcase.zip
>
>
> For more details see the attached testcase. I'm sorry, but in the short of time i only got a testcase for jboss-server 4.2. Please deploy the server.ear from /release-directory and then call the /src/client/TestCaseClient.java.
> [Summarized]
> It seems, that touching a lazy (Persistent-)Collection of at least a m:n relation inside a Hibernate event-listener always raises this error:
> org.hibernate.AssertionFailure: collection [n-side] was not processed by flush()
> [Explanation]
> I have two entities A. and B. Both having a m:n relation between each other. Furthermore there is an PostUpdateListener, which iterates onUpdate of entitiy through all properties of updated entity.
> [Testcase]
> Both entities are linked with eachother (m:n). If i now do a simple update of a property of entity A --> MyPostUpdateListener will be called, which iterates through every property of the updated entity. In case of this property was a collection (= lazy PersistentCollection of m:n relation), hibernate initializes the collection for further work. I can now run through all objects of the collection, but after all work is done in listener, I get the following exception from postFlush:
> Caused by: org.hibernate.AssertionFailure: collection [com.qualitype.testcase.server.ejb.entity.EntityB.entitiesOfA] 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)
> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
> at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
> at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
> ... 29 more
> Attention: EntityB.entitiesOfA is the other-side collection of the m:n relation of the updated EntityA.
> We are using hibernate-event listener system for auditing-purposes, so you should understand that touching every (element in the) collection is necessary for audit-purposes.
> Seems for me like a serious bug. Need this fixed asap ...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list