Show TOC Start of Content Area

Background documentation JTA and Local Transactions  Locate the document in its SAP Library structure

Transactions are one of the most important concepts when working with the persistence layer. Their correct usage guarantees the consistency of the underlying data, as well as the performance of your application. Therefore, it is very important to know what types of transactions you can use in your application components, and how to use them.

The application components that you deploy on the AS Java may deal with two basic types of transactions:

      JTA transactions

These are transactions defined by the Java Transaction API (JTA) standard, therefore we refer to them as JTA transactions.

The following list outlines the most important characteristics of a JTA transaction, which distinguishes it from a local transaction:

       JTA transactions are managed by a transaction manager, which is external to the data store. In the AS Java, it is a part of the Transaction Service.

       Such transactions are distributed – that is, they may involve communication with a number of resource managers. For example, an application may write data to several data stores in the branches of a single distributed transaction. The consistency of data, which is one of the main requirements for a transaction, is ensured because eventually either all branches of the transaction are committed (the changes they do are stored in the data store) or all of them are rolled back (the initial state of the data is restored). This is done using the two-phase commit protocol (2PC).

       JTA transactions use the javax.transaction.xa.XAResource interface, which enables the coordination of the transaction branches.

       JTA transactions are either container- or component-driven. You can demarcate a JTA transaction in certain application components – session and message-driven beans with  bean-managed transaction demarcation, and Web components, or leave the transaction demarcation to the EJB Container. Generally, it is better to use container-managed transactions, because this makes your code more simple, less error-prone, and easier to debug.

       JTA is the Java EE standard for transaction management. It is the most “natural” way for a Java EE application to demarcate its transactions. Moreover, using standard JTA transactions ensures the portability of your application.

Recommendation

Use JTA transactions in your applications. They provide more flexibility than local transactions by enabling work in a distributed environment. 

      Local transactions

The main characteristics of local transactions are the following:

       Unlike JTA transactions, local transactions work with a single resource manager, which manages the transactions.

       You can code local transaction demarcation in your application, but you must use local transactions very carefully. Generally, you may choose to use local transactions in a very simple scenario, which does not require sophisticated transaction management.

More Information

Using Container-Managed JTA Transactions

Using Component-Managed JTA Transactions

Using Local Transactions

End of Content Area