Using JTA Transactions with vFabric GemFire

vFabric GemFire provides an implementation of the Java Transaction API (JTA). JTA is an industry standard for global transactions controlling multiple resources. With JTA, you can write your transactions using the same API, whether they run in J2EE or not. Using GemFire is just like using a database, with the same begin and commit. All the application knows is the JTA level, and the transaction manager handles the rest.

A JTA transaction includes the following parties:
  • The Java application, responsible for starting the global transaction
  • The JTA transaction manager, responsible for opening, committing, and rolling back transactions
  • The transaction resource managers, including the GemFire cache transaction manager and the JDBC resource manager, responsible for managing operations in the cache and database
Note: See the Sun documentation for more information on topics such as JTA, javax.transaction, committing and rolling back global transactions, and the related exceptions.

The GemFire JTA implementation also supports the J2EE Connector Architecture (J2CA) ManagedConnectionFactory.

While a global transaction is running, each cache operation that would participate in a GemFire transaction tries to join through JTA synchronization. If the global transaction has been marked for rollback, however, the GemFire operation is not allowed to join and the cache operation call throws a FailedSynchronizationException.

JTA provides direct coordination between the GemFire cache and another transactional resource, such as a database. Using JTA, your application controls all transactions in the same standard way, whether the transactions act on the GemFire cache, a JDBC resource, or both together. When a JTA global transaction is done, the GemFire transaction and the database transaction are both complete.

The GemFire JTA is initialized when the cache is initialized. If a global transaction exists when you use the cache, the cache operations automatically enlist themselves with the transaction, where appropriate. Operations on a region automatically detect and become associated with the existing global transaction through JTA synchronization. If the global transaction has been marked for rollback, any cache operation that attempts to enlist throws a FailedSynchronizationException.

The GemFire cache transaction's commit or rollback is triggered when the global transaction commits or rolls back. When the global transaction is committed using the UserTransaction interface, the transactions of any registered JTA resources are committed, including the GemFire cache transaction. If the cache or database transaction fails to commit UserTransaction throws a TransactionRolledBackException. If a commit or rollback is attempted directly on a GemFire transaction that is registered with JTA, that action throws an IllegalStateException.

If there are cache writer and cache loader with transactional data sources, the writer and loader participate in the transaction. If the JTA rolls back its transaction, the changes made by the cache loader and the cache writer are rolled back.

You can disable JTA for any region by setting the region attribute ignore-jta to true.