Oct 26th, 2009, 09:30 AM
How to avoid "Could not synchronize database state with session" ?
We're using Spring + Hibernate to insert several hundreds of records into the database. For each record inserted, a method is called which starts a transaction as we need to know individual results for each insert. If the insert fails (as a result of it being a duplicate), we catch the resulting DataIntegrityViolationException, record it, and report the end result (with a summary of all failed records) to the end user.
Everything is working satisfactory. The only thing that is somewhat odd is that our log gets poluted with ERROR level messages from Hibernate:
It complains about "Could not synchronize database state with session" (+ full stack trace) which occurs after each failed insert due to the ConstraintViolationException.
Our theory is that this occurs because Hibernate's Session has a stale reference to the object we're trying to insert and is not properly closed/cleaned/rolled back.
Is there any way we could influence Spring to properly discard the Hibernate session after a ConstraintViolation + rollback occurs? Or any way (apart from supressing the log message) to get rid of this message?
Apr 30th, 2011, 03:12 AM
Even i am facing same problem