Transactions in the Deployment Descriptor


The transactional properties of a bean are defined in three steps.

Step 1

In the first step the bean provider specifies whether transactions are to be managed by the EJB container or the bean. The bean provider gives these instructions exclusively in the bean's deployment descriptor.

In the case of explicit transaction management of the bean, the bean provider defines the transaction type Bean in the bean's deployment descriptor in the segment enterprise-beans:

 <transaction-type>Bean</transaction-type> 

In the case of declarative transaction management no specifications about the transactional properties are made in the bean's deployment descriptor. These are established only in the following steps, with the transaction attributes.

Step 2

In the second step the application assembler defines the transaction attributes. The application assembler makes specifications about the bean exclusively in the section assembly-descriptor.

A separate transaction attribute can be specified for each permitted method. This defines the transactional behavior of the bean with implicit transaction management by the EJB container.

The EJB specification gives precise instructions as to which methods from the home and remote interfaces can be assigned to a transaction attribute:

  • for session beans, only for the defined business methods;

  • for entity beans, for the defined business methods and also for the methods find, create, and remove from the home interface.

The EJB specification specifies three different forms for keeping the definition in the deployment descriptor simple and understandable:

  1. The same transaction attribute is assigned to all methods of a bean:

     <method>   <ejb-name>Stock</ejb-name>   <method-name>*</method-name> </method> 

  2. One transaction attribute is assigned to one method name. If there are several methods with the same name but with differing parameters, then the transaction attribute is assigned to all these methods:

     <method>   <ejb-name>Stock</ejb-name>   <method-name>get</method-name> </method> 

  3. One transaction attribute is assigned to exactly one method. The method is completely specified by its name and parameter types:

     <method>   <ejb-name>Stock</ejb-name>   <method-name>get</method-name>   <method-param>int</method-param> </method> 

    It is possible that methods will exist with identical signatures in the home and remote interfaces. With the additional attribute method-intf one can differentiate between Home and Remote:

     <method>   <ejb-name>Stock</ejb-name>   <method-intf>Home</method-intf>   <method-name>create</method-name>   <method-param>     java.lang.String   </method-param>   <method-param>int</method-param>   <method-param>int</method-param> </method> 

These three systems can also be used simultaneously. In this case the more precise definition always takes precedence over the less precise.

Step 3

In the third step the deployer can change and extend the instructions in the application assembler. The deployer must ensure that for each bean with implicit transaction management a unique transaction attribute is defined for each method.




Enterprise JavaBeans 2.1
Enterprise JavaBeans 2.1
ISBN: 1590590880
EAN: 2147483647
Year: 2006
Pages: 103

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