Hibernate Flush Problem: org.hibernate.AssertionFailure: collection was not processed by flush

At work we had a problem with randomly getting the org.hibernate.AssertionFailure: collection was not processed by flush exception thrown in various places.  After searching for a solution we finally found a blog that mentioned a similar issue and a working solution.

Our base model class had an overridden equals() method and hashCode() method that was causing the problem.  If you have overridden a method used for comparison in collections, such as equals(), hashCode(), compare(), be wary that your method is not causing hibernate to instantiate lazily loaded objects during flush.  We had a complex equals() method that used reflection to compare values within a model.  This is bad practice and the equals method should be overridden to check attributes that form a natural key for the object.  For performance as well as resolving this problem we changed our equals method to do the following:

  1. Check if the objects were the same: obj == otherObj
  2. Check if the objects’ surrogate keys were equal: obj.getId() == otherObj.getId() — or obj.getId().equals(otherObj.getId()), depending on your Id datatype
  3. Check if the objects’ natural/business keys were equal: obj.getSSN().equals(otherObj.getSSN())
Those are just examples and show how we fixed the issue.  The main point is that you should reevaluate your equals, hashCode, and comparator methods to determine if that is causing the flush problem.  Hibernate actually has reasoning and best practices for overriding them that you can follow here.

Credit on my team goes to Reddy Kasireddy, and to the blog where he found it:


4 Responses

  1. JB Says:


  2. CB Says:

    Thanks for giving the hint!
    – I had the same exception, but in my case it was caused by the collection’s @org.hibernate.validator.Size Annotation.

  3. BN Says:


  4. Rana Ranavijay Singh Says:

    this error is not a big deal all you have to do is to change a line in your file …..
    basically in your “*.hbm.xml” file ….

    i had the same problem was solved using this … ..

    I HAD “Employee.hbm.xml” as

    This class contains the employee detail.

    i changed it to .. ..

    This class contains the employee detail.

    and DONE. i hope this helps.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.