Enterprise JavaBeans supports flat transactions, modeled after the OMG Object Transaction Service 1.1 (OTS). An enterprise Bean object that is transaction-enabled corresponds to the TranactionalObject described in OTS.
A client or a non-transactional enterprise Bean can use the javax.jts.UserTransaction interface to explicitly demarcate transaction boundaries. The application programmer demarcates the transaction with begin and commit calls, and the EJB server ensures that the updates to databases are transactional.
Whenever a client invokes an enterprise Bean the container interposes on the method invocation. The interposition allows the container to control transactoin demarcation declaratively through the transaction attribute.
For example, if an enterprise Bean is deployed with the TX_REQUIRED transaction attribute, the container automatically initiates a transaction whenever a client invokes a tranaction-enabled enterprise Bean while the client is not associated with a transaction context.
The transaction attribute is specified in the enterprise Bean's deployment descriptor. A transaction attribute can be associated with the entire Bean (to apply to all methods), or it can be associated with an individual method.
A container must always invoke an enterprise Bean that has the TX_NOT_SUPPORTED transaction attribute without a transaction scope.
An enterprise Bean with the TX_BEAN_MANAGED attribute can use the javax.jts.UserTransaction interface to demarcate transaction bonudaries.
If a client invokes an enterprise Bean that has the TX_REQUIRED transaction attribute while the client is associated with a transaction context, the container invokes the enterprise Bean's method in the client's transactional context.
If the client invokes the enterprise Bean object while the client is not associated with a transaction context, the container automatically starts a new transaction before delegating a method call to the enterprise Bean object, and attempts to commit the transaction when the method call on the enterprise Bean object has completed.
An enterprise Bean object that has the TX_SUPPORTS transaction attribute is invoked in the client's transactional scope. If the client does not have transaction scope, the enterprise Bean is also invoked without a transactional scope.
An enterprise Bean that has the TX_REQUIRES_NEW transaction attribute is always invoked in the scope of a new transaction. The container starts a new transaction before delegating a method call to the enterprise Bean object, and attepmts to commit the tranaction when the method call on the enterprise Bean object has completed. The container performs the commmit protocol before the method result is sent to the client.
An enterprise Bean object that has the TX_MANDATORY attribute is always invoked in the scrope of the client's transaction. If the client attempts to invoke the enterprise Bean without a transaction context, the container throws the TransactionRequired exception to the client.
Copyright © 1998 by Sun Microsystems Inc.