Card 05/ 07

ComparisonDifficulty: Advanced1 min

REQUIRES_NEW vs the Default

bookRideThenFail() calls logIndependently(), then throws. logIndependently is REQUIRES_NEW — and its write survives the caller's rollback entirely.

java
@Transactional(propagation = Propagation.REQUIRES_NEW)
void logIndependently(String note) {
    repo.save(new AuditEntity(note));
}

@Transactional
void bookRideThenFail() {
    auditService.logIndependently("attempted booking");
    throw new RuntimeException("booking failed after logging");
}
text
REQUIRES_NEW audit log survived caller's rollback: count = 1
run in a container — despite the outer method throwing and rolling back
The two propagation values
PropagationWhen called inside an existing transaction
REQUIRED (the default)Joins it — one transaction, one outcome for both
REQUIRES_NEWSuspends the caller's transaction and starts a completely independent one, which commits or rolls back on its own

REQUIRES_NEW is the right call for exactly this shape: an audit entry, a notification, anything that should be recorded regardless of whether the operation it's logging ultimately succeeds. The default, REQUIRED, is right whenever the two pieces of work should genuinely live or die together.