org.hibernate.AssertionFailure: collection was not processed by flush()

Hibernate JIRA | Tom Kucharski | 1 decade ago
  1. 0

    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)

    Hibernate JIRA | 1 decade ago | Tom Kucharski
    org.hibernate.AssertionFailure: collection was not processed by flush()
  2. 0

    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)

    Hibernate JIRA | 1 decade ago | Tom Kucharski
    org.hibernate.AssertionFailure: collection was not processed by flush()
  3. 0

    Hibernate Community • View topic - Strange "collection was not processed by flush()"

    hibernate.org | 7 months ago
    org.hibernate.AssertionFailure: collection was not processed by flush()
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    [1.3.0] When did you plan to release it

    Google Groups | 4 years ago | Alex
    org.hibernate.AssertionFailure: collection [models.User.tags] was not processed by flush()
  6. 0

    I'm getting a weird error that only occurs when the bean validation event listener is being activated. If I remove the constraint annotation, I don't have a problem - the test passes. This is the exception I get: ERROR AssertionFailure:45 - 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 [jawbs.domain.jobseeker.JobSeeker.watchedJobs] was not processed by flush() at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:228) at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:356) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028) at jawbs.DatabaseTests.flush(DatabaseTests.java:89) Here is the code that causes the exception - at the call to sessionFactory.getCurrentSession().flush() (which just happens to be flush() in this test method). @Test public void jobSeekersCanSaveAPreviousResumeWithTheSameName() { JobSeekerResume resume = ( JobSeekerResume ) resumeDao.find( 1 ); resume.setDescription( "new desc." ); resumeDao.save( resume ); flush(); jdbcMap = simpleJdbcTemplate.queryForMap( "select * from resume where resume_id = ?", resume.getId() ); assertEquals( resume.getDescription(), jdbcMap.get( "DESCRIPTION" ) ); } I don't think the mappings are really that important. Basically, "JobSeekerResume" contains a "JobSeeker", and JobSeeker contains many collections. Every time I run the test, I randomly get this error for any of the collections within the JobSeeker object. In the exception above, it just happened to be the "watchedJobs" collection property. It changes every time I run the test. Now, the reason this problem is happening is that my constraint also hits the database. The constraint asks the sessionFactory to open a session, start a transaction, execute a query, close the transaction and then finally close the session. I've also tried it with a StatelessSession instead, but the same problem persists. Here is the query: select count(*) from JobSeekerResume where name = :name and id != :id and jobSeeker.id = :jobSeekerId Here is the constraint code: public boolean isValid( DomainObject domainObject, ConstraintValidatorContext context ) { BeanWrapper beanWrapper = new BeanWrapperImpl( domainObject ); SessionFactory sessionFactory = ( SessionFactory ) ApplicationContextProvider.getBean( "sessionFactory" ); if( enabled && sessionFactory != null ) { logger.debug( "Enabled - Validating constraint with: " ); logger.debug( hql ); StatelessSession session = sessionFactory.openStatelessSession(); Transaction tx = session.beginTransaction(); Query query = session.createQuery( HqlParser.removePeriodsFromParameterNames( hql ) ); for( String parameterName : HqlParser.getParameterNames( hql ) ) { query.setParameter( HqlParser.removePeriodsFromParameterName( parameterName ), beanWrapper.getPropertyValue( parameterName ) ); } boolean result = (Long) query.uniqueResult() == 0; logger.debug( "isValid is returning: " + result ); tx.commit(); session.close(); return result; } return true; } Now, this query is 100% fine in isolation... and by using logging information, everything is working - the query, the sessions are getting closed, etc. as well. It is curious though that if I disable this constraint, the test passes. With this constraint... it does not. Is this a problem with my constraint? With the bean validation event listener? I'd appreciate any help... and if it is a bug, that it gets fixed. Thank you.

    Hibernate JIRA | 7 years ago | Ken Egervari
    org.hibernate.AssertionFailure: collection [jawbs.domain.jobseeker.JobSeeker.watchedJobs] was not processed by flush()

  1. musketyr 4 times, last 4 weeks ago
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.hibernate.AssertionFailure

    collection was not processed by flush()

    at org.hibernate.engine.CollectionEntry.postFlush()
  2. Hibernate
    CollectionEntry.postFlush
    1. org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:144)
    1 frame
  3. Hibernate
    SessionImpl.flush
    1. org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:305)
    2. org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)
    3. org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
    3 frames
  4. pl.softbank.cepik
    CommonDictModrisClient.insert
    1. pl.softbank.cepik.modris.common.client.util.DefaultModrisClient.updateObject(DefaultModrisClient.java:196)
    2. pl.softbank.cepik.modris.dict.common.client.CommonDictModrisClient.insert(CommonDictModrisClient.java:71)
    2 frames