23 December 2005

Hibernate assertion failure

Q: So what is the likely cause of the following Hibernate exception:

[AssertionFailure] (JMS SessionPool Worker-2:) an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session) org.hibernate.AssertionFailure: null id in entry (don't flush the Session after an exception occurs)

A: After much scratching of heads it turns out it was as simple as a mandatory field not filled in on an object being saved.

So why did we get that message? I've no idea. Maybe its due to one or more of these factors:
* We're using MS SQL and the table had an identity column
* We're using Spring's TransactionSynchronizationManager to manage the transaction
* There is some logical explanation based on a thorough understanding of hibernate's internal mechanisms as to why this particular error means a missing mandatory field. I looked at the source code, but couldn't figure it out.

Its likely that the original error got buried somewhere and this one was a side-effect. However we couldn't see anything in our logs.

Well, now we know.

4 comments:

Anonymous said...

hi tim,
Can u please share ur solution with us because i am facing same problem and not been able to solve.

Tim said...

It was literally just an empty value on an entity that was mapped to a non-null field in the database.

Assigning a value solved the problem.

Anonymous said...

Bonjour! Nettie Nickerson . payday loans

Anonymous said...

Good Day! Susan Gillespie . payday loans