user manual
206 BES Developer’s Guide
Declarative transaction management in Enterprise JavaBeans
Transaction attributes
EJBs that use bean-managed transaction have transaction attributes
associated with each method of the bean. The attribute value tells the
container how it must manage the transactions that involve this bean. There
are six different transaction attributes that can be associated with each
method of a bean. This association is done at deployment time by the
Application Assembler or Deployer.
These attributes are:
■
Required: This attribute guarantees that the work performed by the
associated method is within a global transaction context. If the caller
already has a transaction context, then the container uses the same
context. If not, the container begins a new transaction automatically. This
attribute permits easy composition of multiple beans and co-ordination of
the work of all the beans using the same global transaction.
■
RequiresNew: This attribute is used when the method does not want to be
associated with an existing transaction. It ensures that the container begins
a new transaction.
■
Supports: This attribute permits the method to avoid using a global
transaction. This must only be used when a bean's method only accesses
one transaction resource, or no transaction resources, and does not invoke
another enterprise bean. It is used solely for optimization, because it avoids
the cost associated with global transactions. When this attribute is set and
there is already a global transaction, the EJB Container invokes the method
and have it join the existing global transaction. However, if this attribute is
set, but there is no existing global transaction, the Container starts a local
transaction for the method, and that local transaction completes at the end
of the method.
■
NotSupported: This attribute also permits the bean to avoid using a global
transaction. When this attribute is set, the method must not be in a global
transaction. Instead, the EJB Container suspends any existing global
transaction and starts a local transaction for the method, and the local
transaction completes at the conclusion of the method.
■
Mandatory: It is recommended that this attribute not be used. Its behavior is
similar to Requires, but the caller must already have an associated
transaction. If not, the container throws a
javax.transaction.TransactionRequiredException. This attribute makes the
bean less flexible for composition because it makes assumptions about the
caller's transaction.
■
Never: It is recommended that this attribute not be used. However, if used,
the EJB Container starts a local transaction for the method. The local
transaction completes at the conclusion of the method.
Under normal circumstances only two attributes, Required and RequiresNew,
must be used. The attributes Supports and NotSupported are strictly for
optimization. The use of Never and Mandatory are not recommended because
they affect the composibility of the bean. In addition, if a bean is concerned










