Transactional attributes can be specified on a bean-wide basis or on a per-method basis for a bean's remote interface. If attributes are specified at both levels, method-specific values take precedence over bean-wide values. These two should be mixed with care since some combinations are invalid as documented in the restrictions section.
Transactional attributes are specified as part of the bean's property file (see Specifying Transaction Requirements). The following table lists all possible values of the attributes and their associated semantics.
Transaction Management Attribute
|
Purpose
|
TX_BEAN_MANAGED
|
The EJB or method explicitly controls transaction boundaries using the javax.transaction.UserTransaction interface. The container does not manage transactions for this bean.
|
TX_MANDATORY
|
The EJB container invokes the EJB method using the transaction context associated with the calling client. If the client has not started a transaction when the bean is invoked, the container throws the TransactionRequired exception.
|
TX_NOT_SUPPORTED
|
The container invokes the EJB without a transaction context. If a client calls with a transaction scope, the container suspends the association of the transaction with the current thread before delegating the method call to the EJB. When the bean's work is completed, the container resumes the transaction.
|
TX_REQUIRED
|
The container invokes the EJB using the client's transactional context, unless the client does not have one. If the client does not have a transaction in progress, the container automatically starts a transaction before delegating the method call to the bean. The container attempts to commit the transaction when the method call on the bean is completed, unless the transaction was marked for rollback or an exception was raised.
|
TX_REQUIRES_NEW
|
The EJB requires that the container start a new transaction when a method is invoked. The container attempts to commit the transaction when the bean's method call completes. When a client calls into a bean with this attribute, the container suspends the client's transaction before starting the bean's new transaction. Upon completing the bean's transaction, the container resumes the client's suspended transaction.
|
TX_SUPPORTS
|
The EJB mirrors the client's transaction scope. If the client has a transaction context, the EJB is invoked in that context. If not, the EJB is invoked without a transaction context.
|
|