@Transactional(propagation = Propagation.REQUIRES_NEW) makes Spring suspend any transaction that is already running and start a brand-new, independent one for the annotated method. The new transaction commits or rolls back on its own, regardless of what happens to the outer transaction afterwards.
Use it when some work must be saved even if the surrounding operation fails, the classic case being audit logging, or when a failure inside should not poison the caller's transaction.
With the default REQUIRED, an inner call joins the caller's transaction, so everything commits or rolls back together. With REQUIRES_NEW, Spring does this:
The two transactions do not see each other's uncommitted changes under the usual READ_COMMITTED isolation, and a rollback of one does not affect the other.
If charge throws a runtime exception, the payment transaction rolls back, but the audit entry is already committed in its own transaction. That is exactly the point of REQUIRES_NEW.
AuditService is a separate bean, so the call goes through the Spring proxy. Putting record in the same class as pay and calling it with this.record(...) would ignore the annotation.
| Propagation | Outer transaction exists | Inner failure | Outer failure |
|---|---|---|---|
REQUIRED | Joins it | Marks the whole transaction rollback-only | Everything rolls back |
REQUIRES_NEW | Suspends it, starts new | Only the inner work rolls back | Inner work stays committed |
NESTED | Savepoint in the same transaction | Rolls back to the savepoint | Everything rolls back, including the nested part |
NESTED only works with transaction managers that support savepoints, such as JDBC. JPA's default JpaTransactionManager does not support it.
An exception that leaves the REQUIRES_NEW method rolls back the inner transaction and then propagates to the caller, where it will roll back the outer transaction too unless you catch it:
Because the inner transaction was independent, catching the exception here is safe; the outer transaction is not marked rollback-only.
REQUIRES_NEW call needs a second connection while the first is still held. Under load, nested calls inside a loop can exhaust the connection pool and deadlock, because every thread holds one connection and waits for another.Normally yes, because the suspended transaction still holds its connection. Size your pool for the nesting depth you allow.
Yes, once the inner method returns successfully its transaction is committed and stays committed.
Most often self-invocation: the call did not pass through the proxy. Move the method to another bean.
No. REQUIRES_NEW is fully independent, while NESTED is a savepoint inside the outer transaction and rolls back with it.
Propagation.REQUIRES_NEW suspends the current transaction and runs the method in its own, so its commit or rollback is independent of the caller. It suits audit logs and isolated side effects. Call it through another bean, watch connection pool usage and avoid lock conflicts between the two transactions.