[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2763) (lazy) m:n relation + EventListener = AssertionFailure: collection [n-side] was not processed by flush()
Samppa Saarela (JIRA)
noreply at atlassian.com
Fri Jan 9 11:17:43 EST 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2763?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=32094#action_32094 ]
Samppa Saarela commented on HHH-2763:
-------------------------------------
Hibernate-validator may also cause this error. For example
@entity class A {
@ManyToOne(fetch=FetchType.LAZY)
private A previous;
@OneToMany(mappedBy="previous", fetch=FetchType.LAZY)
// THIS CAUSES "collection was not processed by flush()" ERROR:
@Size(min=0, max=1)
private Set<A> next = new HashSet<A>();
@OneToMany(...,fetch=FetchType.LAZY)
private Collection<Whatever> whatever;
}
This example uses ManyToOne in order to avoid problems with OneToOne relation (forces eager load).
When flushing changes to an A#1 which has a non-initialized collection next containing A#2, @Size validator gets executed on pre flush phase and it initializes collection "next" that in turn loads entity A#2. Lazy collections of A#2 (whatever) don't get processed by flush and then raise this error.
There are at least two things to do here: 1) remove @Size wholly or 2) use @LazyCollection(LazyCollectionOption.EXTRA) option on the collection. But it raises also questions about usability of other, e.g. @Valid, validators on lazily intialized properties. Should validators be implemented so that they first check if a value has been initialized or can this be addressed within Hibernate somehow?
> (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
> 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