@Transactional(propagation = Propagation.REQUIRES_NEW) makes Spring suspend the current transaction, if any, and run the method in a brand new, independent transaction. That transaction commits or rolls back on its own, regardless of what happens to the caller. Use it when a piece of work must be saved even if the surrounding operation fails.
Typical examples are audit logs, outbox or notification records, and counters that must reflect an attempt even when the business transaction rolls back.
When a REQUIRES_NEW method is called through a Spring proxy, the transaction manager does the following.
The two transactions do not know about each other. An exception in the inner method rolls back only the inner transaction. A rollback of the outer one does not undo the inner commit.
When PaymentDeclinedException is thrown, the payment row is rolled back, but the audit entry was committed by its own transaction and stays in the database.
AuditService is a separate bean because a call within the same class would bypass the Spring proxy, and the annotation would have no effect.
| Good use | Why it fits |
|---|---|
| Audit and security logging | Must persist even if the main operation fails |
| Recording a failed attempt | The failure itself is the data |
| Isolating a batch item | One item commits or fails independently |
| Sequence or counter tables | Short transaction, quick release of the lock |
Avoid it when the inner work depends on uncommitted data from the outer transaction. The new transaction cannot see it, because the outer transaction has not committed.
Each active REQUIRES_NEW holds a second connection while the first stays checked out. With a pool of 10 connections and 10 threads each entering a REQUIRES_NEW method, every thread holds one connection and waits for another. The pool is empty and the application stalls until the connection timeout fires. Keep the pool larger than the maximum nesting your concurrency can produce, or avoid REQUIRES_NEW in hot paths.
The inner transaction can block on a row the outer transaction has already locked, and the outer one waits for the inner to return. That is a self-deadlock. Do not update the same rows in both transactions.
The inner changes are committed even if the outer transaction later rolls back. That is the purpose, but make sure it is acceptable for the business rule.
With JPA, the inner transaction has a fresh persistence context. Entities loaded in the outer transaction are not managed there, so pass identifiers rather than entity instances.
Yes. The outer connection stays open and in use while a second one is taken from the pool for the inner transaction.
No. They were already committed when the inner method returned. Only the outer work is rolled back.
Most likely the call comes from the same class, so it skips the proxy. Move the method to another Spring bean and inject it.
NESTED uses a savepoint inside the same transaction and commits only with the outer one. REQUIRES_NEW is a fully independent transaction on another connection.
Propagation.REQUIRES_NEW suspends the caller's transaction and runs the method in its own, which commits independently. It is the right tool for audit records and isolated units of work. Call it through another bean, keep the inner transaction short, size your connection pool for the extra connections, and never rely on uncommitted data from the outer transaction.