We're updating the issue view to help you get more done. 

AssertionFailure occurs with listeners on models with many-to-many collection.

Description

The problem occurs when insert or update listener is created on hibernate session on model with many-to-many collection and listener is making some queries with this model.

The listener is needed for checking data integrity , so I need to make some select clauses within this listener.
That is my code from PreInsertEventListener.onPreInsert() method (some lines were removed for clearance) :

//I set this on FlushMode.NEVER because StackOverflowError is thrown
event.getSession().setFlushMode(FlushMode.NEVER);
// Function below makes database query using criteria API
String o = listener.validate(event.getEntity(),event.getSession());
if (o != null) {
// I don't know if this is correct, but why not?? I don't catch this exception in my code and I have auto_close_session and auto_flush_session on true
throw new ConstraintViolationException(o,null,null);
}
// set to default settings
event.getSession().setFlushMode(FlushMode.AUTO);

That's exception from my WebLogic 8.1 server

<2005-05-05 18:05:15 CEST> <Error> <org.hibernate.AssertionFailure> <000000> <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:144)
at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:305)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
at pl.softbank.cepik.modris.common.client.util.DefaultModrisClient.updateObject(DefaultModrisClient.java:196)
at pl.softbank.cepik.modris.dict.common.client.CommonDictModrisClient.insert(CommonDictModrisClient.java:71)

Environment

Hibernate version 3.0.2
Oracle9i

Status

Assignee

Unassigned

Reporter

Tom Kucharski

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

3.0.2

Priority

Major