background image

Summary of Transaction Attributes

<< RequiresNew Attribute | Setting Transaction Attributes >>
<< RequiresNew Attribute | Setting Transaction Attributes >>

Summary of Transaction Attributes

If the client is not associated with a transaction, the container starts a new transaction before
running the method.
You should use the RequiresNew attribute when you want to ensure that the method always
runs within a new transaction.
Mandatory
Attribute
If the client is running within a transaction and invokes the enterprise bean's method, the
method executes within the client's transaction. If the client is not associated with a transaction,
the container throws the TransactionRequiredException.
Use the Mandatory attribute if the enterprise bean's method must use the transaction of the
client.
NotSupported
Attribute
If the client is running within a transaction and invokes the enterprise bean's method, the
container suspends the client's transaction before invoking the method. After the method has
completed, the container resumes the client's transaction.
If the client is not associated with a transaction, the container does not start a new transaction
before running the method.
Use the NotSupported attribute for methods that don't need transactions. Because transactions
involve overhead, this attribute may improve performance.
Supports
Attribute
If the client is running within a transaction and invokes the enterprise bean's method, the
method executes within the client's transaction. If the client is not associated with a transaction,
the container does not start a new transaction before running the method.
Because the transactional behavior of the method may vary, you should use the Supports
attribute with caution.
Never
Attribute
If the client is running within a transaction and invokes the enterprise bean's method, the
container throws a RemoteException. If the client is not associated with a transaction, the
container does not start a new transaction before running the method.
Summary of Transaction Attributes
Table 33­1
summarizes the effects of the transaction attributes. Both the T1 and the T2
transactions are controlled by the container. A T1 transaction is associated with the client that
calls a method in the enterprise bean. In most cases, the client is another enterprise bean. A T2
transaction is started by the container just before the method executes.
Container-Managed Transactions
The Java EE 5 Tutorial · September 2007
1000