9.7.4. Nest Transactions

Task Summary

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 transaction’s. There are two phases, a prepare phase and a commit or 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 CosTransactions::SubtransactionAwareResource interface.
JBoss Enterprise Application Platform's 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.
To create a nested transaction, you create a new transaction within a parent transaction. Refer to Section 9.7.3, “Begin a Transaction” for information on creating a transaction.
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.