Skip to main content

Rollback Rules, Common @Transactional Pitfalls, Transaction Synchronization and Distributed Transactions

Learn Rollback Rules, Common @Transactional Pitfalls, Transaction Synchronization and Distributed Transactions (Phase 15 · Spring Transactions (Essential), Spring Core) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Rollback rules • By default Spring rolls back on unchecked exceptions ( RuntimeException ) and Error ; checked exceptions commit the transaction! Customise: rollbackFor = Exception.class , noRollbackFor = BusinessWarning.class (also rollbackForClassName ). Programmatic: TransactionAspectSupport.currentTransactionStatus().setRollbackOnly() . • Catching and swallowing an exception inside the method prevents rollback (the interceptor never sees it). If an inner REQUIRED call throws and you catch it outside, the shared transaction is already rollback-only : the outer commit throws...

More lessons in Phase 15 · Spring Transactions (Essential)