Monday, July 6, 2015

Rolling back Transactions for checked exceptions

If you are a developer of enterprise applications with Java related technologies, then transaction management is a critical area for your enterprise applications. In transaction management, we have container managed transactions(CMT) and bean managed transactions(BMT).

Most of the scenarios, we would like to go ahead with container managed transactions where you need demarcate the methods of your service layer with the transaction attributes. When using container managed transactions, it rollbacks the transactions only for run time exceptions either you used EJB or Spring transactions.

But, there might be some requirements to rollback your transactions for specific checked exceptions as well. Here if you are using EJB CMT, then your specific checked exception class needs to be applied with @ApplicationException(rollback=true) annotation.

But in Spring, the approach is more flexible as you don't need to apply any annotations for exception class. You have more options with the below attributes with roll backing transaction along with the @Transactional annotation.


  1. rollbackForOptional array of exception classes that must cause rollback.
  2. rollbackForClassNameOptional array of names of exception classes that must cause rollback.
  3. noRollbackForOptional array of exception classes that must not cause rollback
  4. noRollbackForClassNameOptional array of names of exception classes that must notcause rollback 

No comments:

Post a Comment