Java Reference
In-Depth Information
Primarily, what we need to configure is our bean's behavior if one of its methods is
called while a transaction is in progress. Should the bean's method become part of
the existing transaction? Should the existing transaction be suspended and a new
transaction created just for the bean's method? We can configure these behaviors
via the @TransactionAttribute annotation.
The @TransactionAttribute annotation allows us to control how an EJB's methods
will behave both when invoked while a transaction is in progress and when invoked
when no transaction is in progress. This annotation has a single value attribute
that we can use to indicate how the bean's method will behave in both of these
circumstances.
The following table summarizes the different values that we can assign to the
@TransactionAttribute annotation:
@TransactionAttribute value
Method invoked
when a transaction
is in progress
Method invoked when no transaction
is in progress
TransactionAttributeType.
MANDATORY
Method becomes
part of the existing
transaction
TransactionRequiredException
is thrown
TransactionAttributeType.
NEVER
RemoteException
is thrown
Method is executed without any
transaction support
TransactionAttributeType.
NOT_SUPPORTED
Client transaction
is temporarily
suspended, the
method is executed
without transaction
support, and then
the client transaction
is resumed
Method is executed without any
transaction support
TransactionAttributeType.
REQUIRED
Method becomes
part of the existing
transaction
A new transaction is created for the
method
TransactionAttributeType.
REQUIRES_NEW
Client transaction
is temporarily
suspended, a
new transaction
is created for the
method, and then
the client transaction
is resumed
A new transaction is created for the
method
TransactionAttributeType.
SUPPORTS
Method becomes
part of the existing
transaction
Method is executed without any
transaction support
Search WWH ::




Custom Search