RuntimeException and Error trigger a rollback; a checked exception commits unless you say otherwise.
@Transactional
public void a() throws Exception {
save();
throw new Exception("checked"); // COMMITS
}
@Transactional(rollbackFor = Exception.class)
public void b() throws Exception {
save();
throw new Exception("checked"); // rolls back
}
a(): the row is still there.
b(): the row is gone.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11