Transaction propagation defines how transactions behave when one method calls another method.
It controls whether a method should join an existing transaction or create a new one.
@Transactional(propagation = Propagation.REQUIRED)
| Type | Description |
|---|---|
| REQUIRED | Join existing or create new |
| REQUIRES_NEW | Always create new transaction |
| SUPPORTS | Join if exists, else non-transactional |
| NOT_SUPPORTED | Run without transaction |
| MANDATORY | Must have existing transaction |
| NEVER | Must not have transaction |
| NESTED | Nested transaction (savepoint) |
ServiceA (TX) ↓ ServiceB (joins same TX)
ServiceA (TX1) ↓ ServiceB (TX2 - new)
If TX exists → join Else → run without TX
MANDATORY → throws exception if no TX NEVER → throws exception if TX exists
Outer TX ↓ Inner TX (Savepoint) ↓ Rollback inner only if needed
REQUIRED → Join or create REQUIRES_NEW → Always new SUPPORTS → Optional