The @Transactional(propagation = Propagation.REQUIRES_NEW) annotation forces Spring to always run a method in a new transaction. If a transaction is already active, Spring suspends it for the duration of the method, then resumes it afterwards. The new transaction commits or rolls back independently of the outer one.
This is how you isolate a unit of work so that its outcome does not depend on, and does not affect, the surrounding business transaction.
Transaction state in Spring is bound to the current thread through TransactionSynchronizationManager. When REQUIRES_NEW is hit, the transaction manager:
You can see this in the logs with logging.level.org.springframework.transaction.interceptor=TRACE or org.springframework.orm.jpa=DEBUG; the output shows "Suspending current transaction, creating new transaction".
Typical situations where independence is the goal:
Each item commits separately. A failure on item 57 rolls back only item 57. Note that importAll has no transaction of its own; if it did, REQUIRES_NEW would still work but would hold an extra connection for the whole loop.
| Situation | Result |
|---|---|
| Inner method succeeds, outer later fails | Inner stays committed |
| Inner throws runtime exception, outer catches it | Inner rolls back, outer can still commit |
| Inner throws runtime exception, outer does not catch it | Both roll back |
| Inner throws checked exception | Inner commits unless rollbackFor is set |
The default rollback rule still applies inside the new transaction: only RuntimeException and Error trigger rollback. Add rollbackFor = Exception.class if checked exceptions should roll back too.
this skips the proxy, so no new transaction starts. Place it on a different bean.REQUIRES_NEW holds an extra connection. With a pool of 10 and 10 concurrent outer transactions each requesting a second connection, all threads wait forever. Keep nesting shallow and the pool large enough.READ_COMMITTED, the new transaction cannot read rows the outer transaction has changed but not committed.Tests marked @Transactional roll back at the end, but a REQUIRES_NEW call commits for real. Clean up the data it creates, or use a disposable database such as Testcontainers, and assert on the committed rows after the outer call fails.
REQUIRED joins an existing transaction, so everything succeeds or fails together. REQUIRES_NEW always starts a separate one and suspends the existing one.
No. Proxy-based transactions only intercept calls from outside the bean to public methods, so annotate a public method on a different bean.
Transaction state is bound to a thread, so it does not follow @Async calls. Reactive code uses TransactionalOperator and a reactive transaction manager instead.
At least two per thread at the point of nesting. Plan pool size accordingly.
Propagation.REQUIRES_NEW suspends the current transaction and executes the method in a separate transaction that commits or rolls back on its own. It is right for audit records, per-item batch work and other isolated side effects, and wrong as a default. Call it through another bean, size your connection pool for the extra connection and think through locking and visibility.