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.
- rollbackFor - Optional array of exception classes that must cause rollback.
- rollbackForClassName - Optional array of names of exception classes that must cause rollback.
- noRollbackFor - Optional array of exception classes that must not cause rollback
- noRollbackForClassName - Optional array of names of exception classes that must notcause rollback
No comments:
Post a Comment