Transactions

Defining transactions within or across beans is done via annotations. This takes the complexity out of the deployment descriptor however it's just as easy to define transaction boundaries from the descriptor.

Transaction Type

By default, session and message-driven beans will be generated with a @TransactionAttribute annotation with a value of REQUIRED. To overwrite this value, simply model the andromda_ejb_transaction_type tagged value on the class level or bean method level.

The EJB 3.0 spec defines that the transaction management type cannot be specified for EJB 3.0 entity POJOs. These entities execute within the transactional context of the caller, which is the DAO or session bean.

The DAO base class also specifies the transaction attribute as REQUIRED. Remember your business logic resides in the session facade using the DAO API interface; hence you control your transactions from your session beans.

Your TransactionAttributeType options are:

  • Mandatory
  • Never
  • NotSupported
  • Required
  • RequiresNew
  • Supports

Transaction Demarcation

The transaction demarcation strategy would normally not be set as the default is CONTAINER managed transaction demarcation. If you want to specify BEAN managed transaction demarcation, model the andromda_ejb_transaction_management tagged value to BEAN.

If you specify BEAN managed transaction demarcation, the cartridge will inject an instance of UserTransaction into variable name userTrans to manually define your transaction.

Next

To learn about manageable entities, click here.