2012-01-16

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...

9 comments:

  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

      Delete
  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.

    ReplyDelete

  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 - 대구오피
    (jk)

    ReplyDelete
  4. Nice Many Thanks for sharing this awesome content you provide to all your reader's. Really appreciate it. 야한동영상

    Also feel free to visit may webpage check this link
    야설

    ReplyDelete
  5. Thanks for sharing. I found a lot of interesting information here. Thank you for this fascinating post, I am happy I observed this website on Google. Not just content, in fact, the whole site is fantastic. 일본야동

    Also feel free to visit may webpage check this link
    한국야동

    ReplyDelete
  6. I found this is an informative blog and also very useful and knowledgeable. Thank you for posting such a great article! I found your website perfect for my needs. It contains wonderful and helpful posts. Keep up the good work!. Thank you for this wonderful Article! 한국야동닷컴

    Also feel free to visit may webpage check this link
    국산야동

    ReplyDelete
  7. Just as powerful, just as strong, and just as well funded. I was very interested in the article. it’s quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one. 국산야동

    Also feel free to visit may webpage check this link
    야설

    ReplyDelete
  8. Thank you for sharing excellent information. Your web-site is so cool. I am impressed by the details that you've on this blog. 중국야동넷

    Also feel free to visit may webpage check this link
    야설

    ReplyDelete