Hibernate - collection was not processed by flush

Recently I got the following exception from Hibernate:
collection was not processed by flush
What happened? I have the following class structure.
Artist -> Album -> Song (parent -> child)

Library -> Stat (parent -> child)

Song - Stat (association)
Artist and Library are aggregates in DDD sense. Artist is the parent of Album, Album is the parent of Song. Library is the parent of Stat. What's important, there's also a bidirectional relationship between Song and Stat (but no ownership). The exception occurred in the following situation:
  1. I had an Artist with one Album with one Song that had an association with one Stat being a child of its Library and that was created in Transaction 1.
  2. In Transaction 2, the whole thing was loaded again, a new Stat added, being a child of a new Library.
  3. Transaction 2 ended. Exception thrown.
So at the time when Transaction 2 ended I had a Song with 2 Stats, each referring to a different Library, but one of those Libraries was out of context, as it is lazy loaded from Stat.

The fix

The fix (or hack) was to eagerly load Library from Song. It's not ideal but it fixed the problem. There was no need to update this Library instance when transaction ended, so I'm wondering if it's a Hibernate defect...


  1. Replies
    1. Great Article android based projects

      Java Training in Chennai

      Project Center in Chennai

      Java Training in Chennai

      projects for cse

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. Amazing & Great informative blog,it gives very useful practical information to developer like me. Besides that Wisen has established as Best Hibernate Training in Chennai . or learn thru Online Training mode Hibernate Online Training | Java EE Online Training. Nowadays Hibernate ORM has tons of job opportunities on various vertical industry.


  3. I blog quite often and I truly appreciate your content.
    This article has really peaked my interest.
    I’m going to book mark your blog and
    keep checking for new details about once a week.
    I subscribed to your Feed as well.

    Also visit my webpage - 대구오피