UnexpectedRollbackException - a full scenario analysis

exception, hibernate, java, spring

Solution

Scroll a little more back in the log (or increase it's buffer-size) and you will see what exactly caused the exception.

If it happens not to be there, check the `getMostSpecificCause()` and `getRootCause()` methods of `UnexpectedRollbackException`- they might be useful.

Problem

All I know about this exception is from Spring's documentation and some forum posts with frostrated developers pasting huge stack traces, and no replies. From Spring's documentation: Thrown when an attempt to commit a transaction resulted in an unexpected rollback I want to understand once and for all Exactly what causes it? - Where did the rollback occur? in the App Server code or in the Database? - Was it caused due to a specific underlying exception (e.g. something from java.sql.*)? - Is it related to Hibernate? Is it related to Spring Transaction Manager (non JTA in my case)? How to avoid it? is there any best practice to avoid it? - How to debug it? it seems to be hard to reproduce, any proven ways to troubleshoot it?

Original source