Transaction management


How it works

When a component is transactional and uses the EJB Server connection management feature, commands sent to a data source are automatically performed as part of a transaction. Component methods can call EJB Server’s transaction state primitives to influence whether EJB Server commits or aborts the current transaction.

The EJB Server coordinates the database activity of all transactional components participating in the transaction. The application can roll back everything that took place in the transaction if any component could not complete its part of the work.

StepsTo define how a component participates in transactions:

  1. Choose a transaction coordinator for the EJB Server. The transaction coordinator manages the flow of transactions that involve more than one connection and sometimes more than one data source.

  2. Set the component's transaction attribute to determine how the component participates in transactions.

  3. Code methods to call EJB Server’s transaction state primitives to influence the transaction outcome.

Each task is described in detail below.


Choosing a transaction coordinator

The transaction coordinator manages the flow of transactions that involve more than one connection and sometimes more than one data source. To enable transactions involving multiple data sources, you must configure your EJB Server to use a transaction coordinator that supports two-phase commit, such as OTS/XA.


Setting the transaction attribute

Each EJB Server component has a transaction attribute that determines how instances of the component participate in transactions. Values are:

Attribute

Description

Requires Transaction

The component always executes in a transaction. Use this option when your component’s database activity needs to be coordinated with other components, so that all components participate in the same transaction.

Requires New Transaction

Whenever the component is instantiated, a new transaction begins.

Supports Transaction

The component can execute in the context of an EJB Server transaction, but a transaction is not required to execute the component's methods. If a method is called by a base client that has a pending transaction, the method’s database work occurs in the scope of the client’s transaction. Otherwise, the component’s database work is done outside of any transaction.

Not Supported

The component's methods never execute as part of a transaction. If the component is activated by a client that has a pending transaction, the component’s work is performed outside the existing transaction.

Mandatory

Component methods must be called in the context of a pending transaction. If a client calls a method without an open transaction, the EJB Server ORB throws an exception.

Bean Managed

For EJB session Beans only. The component can explicitly begin, commit, and rollback new, independent transactions by using the javax.transaction.UserTransaction interface. Transactions begun by the component execute independently of the client’s transaction. If the component has not begun a transaction, the component’s database work is performed independently of any EJB Server transaction.


Influencing transaction outcome

If your component participates in EJB Server transactions, you can call transaction state primitives to explicitly commit or roll back database updates performed in a method.

Components that use the Bean Managed or OTS Style transaction attribute must explicitly begin and end transactions using the APIs described below. For components that use any other attribute, EJB Server implicitly commits each method’s work when the method returns unless the method has requested rollback.

Different component types use different transaction APIs: