EJB 3.0 – Nested Transaction != Requires New?

RequiresNew does not create a nested transaction because the first transaction is suspended while the second transaction is running. A nested transaction looks like this:

Nested transaction example
> method1 - begin tran1
  > method2 - begin tran2
    workA
  < method2 - commit tran2
< method1 - rollback tran1 (tran2 also rolled back because it's nested)

Instead, RequiresNew looks like this:

EJB RequiresNew example
> method1 - begin tran1
  > method2 - suspend tran1, begin tran2
    workA
  < method2 - commit tran2, resume tran1
< method1 - rollback tran1 (tran2 remains committed)

Simple answer is the “outer” transaction is suspended before the new transaction is started. The fates of the two transactions are not in any way linked, so by all intents and purposes one is not nested into another.

If the REQUIRES_NEW method throws an EJBException it is the new transaction it created that will be rolled back, not the “outer” transaction.

Leave a Comment