Hibernate relations and event listeners 1

Posted by Jens Jäger on January 24, 2012

In my current project I work on a Java EE application with a hibernate backend. The applications supports two databases MSSql and Oracle. The development started with MSSql. One of my tasks was to migrate the application to Oracle. We expected some problems with Spring ACLs which uses SQL instead of OR Mapping. To fix that I just had to write some custom SQL for Oracle.

After handling the ACLs I got transaction problems with oracle, we hadn’t with MSSql. After some tests and research I found out that to fix this I had to add a entityManager.flush(); to the persist and merge method of our entity manager. I was happy to resolved the issue an started our test suite.

Then I run into an exception like this:

I got this exception on our local H2-database on MSSql and Oracle. After some research I found this issue in the hibernate Jira:

HHH-2763: Allow initialization during flush

In the first place I ignored it because the entry was from 2007. After some more research and some tests I found out that our problem looked similar to the issue reported to hibernate. We had relations and we had listeners in the form of PrePersistCallbacks and PreUpdateCallbacks. I couldn’t believe that an issue from 2007 was still not fixed.

My next step was to write a test case to reproduce the error. The test case is very domain specific so I can’t post it here.

I found out that the bug was already fixed in grails. With this knowledge it was easy to came to this solution:

To make this work in our application I had to add this spring configuration to our applicationContext-datasource.xml:

The problem occurred with Hibernate 3.6.7.Final which was the latest stable release by the time I run into it. It should be fixed in Hibernate 4.0.0.Final or later which final release was in december.


Use this link to trackback from your own site.


Leave a response

  1. Play Framework 2: Ebean vs. JPA - jensjaeger.com Sun, 17 Nov 2013 22:12:21 CET

    […] implementations like hibernate have bugs as well. But in the end even the nasty ones like HHH-2763, finally get fixed. JPA knowledge is also widely […]


Information about Data protection