Suggested Pages

Wednesday, April 15, 2015

Spring Rollback

Let's us suppose to have a transaction with a Declarative transaction management into Spring Framework and you are in the situation where an unchecked exception can be thrown.

Unless of particular configurations Spring makes a rollback of the transaction only if an uncaught exception arrives to the transactional proxy.

If you catch that exception (for logging purpose), the transaction does not roll back automatically, you can make three possible actions:

  • Rethrow the exception ( the unchecked exception);
  • Throw a new checked application exception marked to cause rollback: @Transactional(rollbackFor = YourException.class);
  • Rollback manually: sessionContext.setRollbackOnly().

Suggested Posts:

No comments :

Post a Comment

Suggested Pages