Originally published at Shipped Code .
You put @Transactional on a service method, an exception is thrown halfway through, and the first row is still in the database. Usually one of 2 things happened. The call never went through Spring's proxy, so there was no transaction at all, or the exception was a checked one, which commits by default. Most of the other pitfalls come from propagation. An inner REQUIRED method that fails dooms the whole outer transaction, while REQUIRES_NEW commits on its own.
Pitfall Symptom Fix
Self-invocation ( this.place() ) No transaction, rows saved before the exception stay Call through another bean, or use TransactionTemplate
Checked exception Method throws, data is committed anyway Throw unchecked domain exceptions; rollbackFor when you can't
Swallowed inner failure UnexpectedRollbackException at commit Don't catch and continue, or give the inner call REQUIRES_NEW
Audit row under REQUIRED Audit disappears with the failed operation REQUIRES_NEW for the audit write (needs a…