background image

Setting Transaction Attributes

<< Summary of Transaction Attributes | Rolling Back a Container-Managed Transaction >>
<< Summary of Transaction Attributes | Rolling Back a Container-Managed Transaction >>

Setting Transaction Attributes

In the last column of
Table 33­1
, the word None means that the business method does not
execute within a transaction controlled by the container. However, the database calls in such a
business method might be controlled by the transaction manager of the DBMS.
TABLE 33­1
Transaction Attributes and Scope
Transaction Attribute
Client's Transaction
Business Method's Transaction
Required
None
T2
T1
T1
RequiresNew
None
T2
T1
T2
Mandatory
None
error
T1
T1
NotSupported
None
None
T1
None
Supports
None
None
T1
T1
Never
None
None
T1
Error
Setting Transaction Attributes
Transaction attributes are specified by decorating the enterprise bean class or method with a
javax.ejb.TransactionAttribute
annotation, and setting it to one of the
javax.ejb.TransactionAttributeType
constants.
If you decorate the enterprise bean class with @TransactionAttribute, the specified
TransactionAttributeType
is applied to all the business methods in the class. Decoration a
business method with @TransactionAttribute applies the TransactionAttributeType only
to that method. If a @TransactionAttributeannotation decorates both the class and the
method, the method TransactionAttributeType overrides the class
TransactionAttributeType
.
The TransactionAttributeType constants encapsulate the transaction attributes described
earlier in this section.
Required
: TransactionAttributeType.REQUIRED
RequiresNew
: TransactionAttributeType.REQUIRES_NEW
Mandatory
: TransactionAttributeType.MANDATORY
NotSupported
: TransactionAttributeType.NOT_SUPPORTED
Container-Managed Transactions
Chapter 33 · Transactions
1001