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:
http://www.jroller.com/jshingler/entry/org_hibernate_assertionfailure_collection_was

 

15 Responses

  1. JB Says:

    THANKS!!!!

  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:

    Thanks

  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.

  5. ways to get more pinterest followers Says:

    This site truly has all the info I wanted about
    this subject and didn’t know who to ask.

  6. visit bangalore mysore Says:

    The city is also a paradise for shopping enthusiasts.
    Probably because of its location on top of the largest plateau, the weather remains cool for most time of the year.
    This hotel which was known as The Grand Ashok in the past is located in the midst of beautifully landscaped gardens that make it hard to
    believe whether you are really in the centre of the bustling city.

  7. 9q Says:

    Then, move the mouse whilst holding down the left click segment
    of the mouse. It has enhanced communication, interaction and understanding of billions of subject only a click away.
    Computer cleanup software can be your response.

    Also visit my page – 9q

  8. W4 Says:

    Touch Mouse is backed by a worldwide three-year restricted hardware guarantee.

    Payday loans are quick, easy and available, if taken with care and caution.
    My working experience shows me that they can.

    Feel free to visit my webpage: W4

  9. 3v Says:

    In the default problem, Windows maintain twenty%
    of bandwidth. There are a number of promotional products out there in the on the net stores.

    These two elements are embedded in the Printed Circuit Board (PCB).

    Feel free to visit my blog post – 3v

  10. Vm Says:

    And also a 64-bit processor will soon to be the common.
    Soft material will make them obtain your specific usage. You have to be eye-catching, striking and entertaining at the exact same time.

    Look into my webpage – Vm

  11. kA Says:

    It requires plenty of perseverance and patience to achieve the career.
    Connection is the up coming factor that we want to speak about.

    System viruses are proving to be fatal trigger of crashing
    pc process.

    my blog post; kA

  12. Fo Says:

    The Mickey Mouse is genuinely a large deal and its recognition past doubt has been in
    the ascendancy. There is a tiny arrow that appears on your pc display when you begin the personal computer up.

    My weblog Fo

  13. fuzion pirates cheats Says:

    A selection of neat video games now are out there for all ages,
    wijth options that remarkably make interesting adventures in the vicinity of to
    truth.The online games advertise reasonable motion scenes owing to their properly-made
    graphics and types.

  14. Dr Dre Beats Says:

    I like looking through a post that can make people think.

    Also, many thanks for allowing for me to comment!

  15. ヴィヴィアンウエストウッド ネックレス Says:

    I’m amazed, I have to admit. Seldom do I come across a blog that’s both educative and engaging, and without a doubt, you have hit the nail on the head.
    The problem is something that not enough folks are speaking intelligently about.
    I’m very happy that I came across this during my hunt for something concerning this.

Leave a Comment

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