Nested transactions are only supported when you use distributed transactions, with the JTS API. In addition, many database vendors do not support nested transactions, so check with your database vendor before you add nested transactions to your application.
The OTS specifications allow for a limited type of nested transaction, where the subtransaction commit protocol is the same as a top-level transactions. There are two phases, a
prepare phase and a
abort phase. This type of nested transaction can lead to inconsistent results, such as in a scenario in which a subtransaction coordinator discovers part of the way through committing that a resources cannot commit. The coordinator may not be able to tell the committed resources to abort, and a heuristic outcome occurs. This strict OTS nested transaction is available via the
The JBoss EAP 6 implementation of JTS supports this type of nested transaction. It also supports a type of nested transaction with a multi-phase commit protocol, which avoids the problems that are possible with the strict OTS model. This type of nested transaction is available via the
ArjunaOTS::ArjunaSubtranAwareResource. It is driven by a two-phase commit protocol whenever a nested transaction commits.
The effect of a nested transaction depends on upon the commit/roll back of its enclosing transactions. The effects are recovered if the enclosing transaction aborts, even if the nested transaction has committed.