Transaction Attributes

Transaction attributes specify the transactional behavior in an EJB. They indicate how a transaction should behave or originate. You can set the attributes for an entire bean or fine-grain it to the level of each bean's business methods, if required. Depending on how your transaction is managed, you can define transaction attributes for container-managed as well as bean-managed transactions.

Transaction Attributes for Container-Managed Transactions

Transactional attributes are specified in the deployment descriptor ejb-jar.xml, with the transaction-type element set to Container. There are six transaction attributes:

  • NotSupported A method with this attribute will never execute in the context of the transaction. If the calling program is associated with a transaction, the container suspends that transaction and allows the method to execute without any transaction support. Once the method is executed, it resumes the calling program transaction.

  • Supports A method with this attribute will participate in the transaction if the calling program is already associated with it, or else it will be executed in the nontransactional mode. This also means that by itself the method will not be responsible for starting a transaction if the calling program is not associated with the transaction.

  • Required A method with this attribute will always be executed in the context of a transaction. Therefore, if the calling program is not associated with the transaction, the container will create a new transaction and will commit it when the method completes.

  • RequiresNew A method with this attribute will always be executed in the context of a new transaction. Whether or not the calling program is associated with the transaction, it will always be executed within a new transaction, that was created by the container. Once the method is executed, the calling program's transaction is resumed, as long as the calling program was already associated to the transaction.

  • Mandatory A method with this attribute must always be called from a program that is associated with a transaction, or else the container will throw a javax.transaction.TransactionRequiredException.

  • Never A method with this attribute will never execute in the context of a transaction. If the calling program is associated with a transaction context, the container will throw a javax.transaction.RemoteException.

Transaction Attributes for Bean-Managed Transactions

In bean-managed transactions, the bean provider specifies the transaction demarcation in the bean implementation, using methods in javax.transaction.UserTransaction. The transaction-type element is set to Bean in the deployment descriptor ejb-jar.xml. Entity beans do not support bean-managed transactions.



Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net