9.5. Transactional Aspects

Because a transactional context cannot be carried by a message (according to the EJB 2.1 specification), an MDB will never execute within an existing transaction. However, a transaction may be started during the onMessage method execution, either due to a "required" transaction attribute (container-managed transaction) or because it is explicitly started within the method (if the MDB is bean-managed transacted). In the second case, the message receipt will not be part of the transaction. In the case of the container-managed transaction, the container starts a new transaction before de-queuing the JMS message (the receipt of which will, thus, be part of the started transaction), then enlist the resource manager associated with the arriving message and all the resource managers accessed by the onMessage method. If the onMessage method invokes other Enterprise Beans, the container passes the transaction context with the invocation. Therefore, the transaction started at the onMessage method execution may involve several operations, such as accessing a database (via a call to an Entity Bean, or by using a "datasource" resource), or sending messages (by using a "connection factory" resource).