Thursday 3 December 2015

Spring, getSingleResult and RollbackException

Slipped up on the rollback exception banana skin again...

Let's have a recap, you get something like this in your logs:

Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly

What's happened?  Well somewhere in your transaction something got the hump and set the transaction rollback flag.  When the transaction tries to commit it sees this, rolls back and dumps that unhelpful message in your logs.  If you want to get forensic get your debugger out and follow these instructions to track down the culprit.