Results 1 to 2 of 2

Thread: How to avoid "Could not synchronize database state with session" ?

  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Default How to avoid "Could not synchronize database state with session" ?

    Hi all,

    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?

    Thanks,
    --John

  2. #2
    Join Date
    Apr 2011
    Posts
    9

    Default

    Even i am facing same problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •