Skip to content
Ameen Abozaid
Planned lessonJNR-031-L04

Rollback rules

  • Lesson 4 of 8
  • Junior
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

java
@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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.