Rollback rules
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
know what triggers a rollback.
Planned topics
- Default: rollback on unchecked exceptions (
RuntimeException,Error). - Checked exceptions commit by default.
- Change with
@Transactional(rollbackFor = Exception.class)or make your business exceptions unchecked. - If you catch an exception and do not rethrow it, the proxy never sees it: no rollback.
- Mark rollback only manually (
setRollbackOnly) in rare cases.
Draft outline details
Demonstration
@Transactional(rollbackFor = PaymentException.class) // checked exception
public void pay(...) throws PaymentException { ... }Check your understanding
Does a checked exception roll back by default?
Show answer
No, it commits.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.