uCosminexus Application Server, EJB Container Functionality Guide

[Contents][Glossary][Index][Back][Next]

2.7.3 CMT

CMT is a model that performs transaction management in the EJB container. The CMT target is the Session Beans, Entity Beans, and the Message-driven Beans. In CMT, you specify the transaction attributes for each method of Bean. Note that the transaction attributes are set as attributes (properties) of the Session Beans, Entity Beans, or the Message-driven Beans included in a J2EE application. For details on the J2EE application settings, see 2.7.4 Defining in cosminexus.xml.

When a transaction cannot be committed, the EJB container performs the following processing:

  1. Logging of application errors
  2. Transaction rollback
  3. Destroying Bean instances
  4. Throwing exception java.rmi.RemoteException in the client invoked by the remote component interface, and exception javax.ejb.EJBException in the client invoked either by the local component interface or by the business interface. If, however, the remote business interface inherits java.rmi.Remote, the exception java.rmi.RemoteException is thrown.
Organization of this subsection
(1) Types of transaction attributes and their behavior
(2) Transaction attributes that can be specified for each type of Enterprise Bean
(3) Transaction attributes of a Stateful Session Bean (SessionSynchronization)

(1) Types of transaction attributes and their behavior

The behavior of transaction attributes is explained in the figures below, for each type of transaction attribute:

NotSupported attribute

If the client invokes the business methods of an Enterprise Bean within the transaction scope, the transaction context is not propagated in the Enterprise Bean. Also, if the client invokes the business methods of the Enterprise Bean outside the transaction scope, the transaction context is again not propagated in the Enterprise Bean.

The following figure shows the behavior of the NotSupported attribute:

Figure 2-7 NotSupported attribute

[Figure]

Required attribute

If the client invokes the business methods of an Enterprise Bean within the transaction, the transaction context is propagated in the Enterprise Bean, and the business methods of the Enterprise Bean enter the transaction scope of the caller. If the client invokes the business methods of the Enterprise Bean outside the transaction scope, a new transaction is started in the Enterprise Bean.

The following figure shows the behavior of the Required attribute:

Figure 2-8 Required attribute

[Figure]

Supports attribute

If the client invokes the business methods of an Enterprise Bean within the transaction, the transaction context is propagated in the Enterprise Bean, and the business methods of the Enterprise Bean enter the transaction scope of the caller. If the client invokes the business methods of the Enterprise Bean outside the transaction scope, the transaction context is not propagated in the Enterprise Bean.

The following figure shows the behavior of the Supports attribute:

Figure 2-9 Supports attribute

[Figure]

RequiresNew attribute

If the client invokes the business methods of an Enterprise Bean within the transaction scope, the EJB container starts a new transaction. Even if the client invokes the business methods of the Enterprise Bean outside the transaction scope, a new transaction is started by the EJB container, in the same way.

The following figure shows the behavior of the RequiresNew attribute:

Figure 2-10 RequiresNew attribute

[Figure]

Mandatory attribute

If the client invokes the business methods of an Enterprise Bean within the transaction, the transaction context is propagated in the Enterprise Bean, and the business methods of the Enterprise Bean enter the transaction scope of the caller. If the client invokes the business methods of the Enterprise Bean outside the transaction scope, the EJB container throws the following exceptions in the client:

The following figure shows the behavior of Mandatory attribute:

Figure 2-11 Mandatory attribute

[Figure]

Never attribute

If the client invokes the business methods of an Enterprise Bean within the transaction scope, the EJB container throws the following exceptions in the client:

If the client invokes the business methods of the Enterprise Bean outside the transaction scope, the transaction context is not propagated in the Enterprise Bean.

The following figure shows the behavior of the Never attribute:

Figure 2-12 Never attribute

[Figure]

(2) Transaction attributes that can be specified for each type of Enterprise Bean

The following table describes the transaction attributes and the default values that can be specified for each type of Enterprise Bean. The transaction attributes that can be specified for each type of Bean are defined in the EJB specifications. CMP 2.0 is considered as optional in the EJB specifications, and other transaction attributes cannot be specified. The default value is not defined in the EJB specifications.# For an application server, when CMT is specified in the DD of EJB, and the transaction attribute is not specified, the default setting will be as shown in the table below:

Table 2-18 Transaction attributes and default values that can be specified for each type of Enterprise Bean

Type Transaction attribute that can be specified Default value
Stateless Session Bean
Stateful Session Bean
(other than SessionSynchronization)
Entity Bean (BMP, CMP 1.1)

  • Supports
  • NotSupported
  • Required
  • RequiresNew
  • Mandatory
  • Never
Supports
Stateful Session Bean
(SessionSynchronization)

  • Supports
  • NotSupported
  • Required
  • RequiresNew
  • Mandatory
  • Never
Required
Singleton Session Bean
(Except PostConstruct/PreDestroy) #1

  • Supports
  • NotSupported
  • Required
  • RequiresNew
  • Mandatory
  • Never
Required
Entity Bean (CMP 2.0)
  • Required
  • RequiresNew
  • Mandatory
Required
Message-driven Bean (when using a resource adapter in compliance with Connector 1.0)
  • Required
  • NotSupported
Required
Message-driven Bean (when using a resource adapter in compliance with Connector 1.5)
  • Required#2
  • NotSupported
Required#2
Session Bean without a DD using annotations
  • Supports
  • NotSupported
  • Required
  • RequiresNew
  • Mandatory
  • Never
Required

Note:
The default value (Required) is, however, defined for an Enterprise Bean that does not have a DD.

#1
With Application Server, even if you specify a transaction attribute in the lifecycle callback method (PostConstruct or PreDestroy) of Singleton Session Bean, it is not effective.

#2
Cannot be specified for the CJMSP resource adapter or FTP inbound adapter.

(3) Transaction attributes of a Stateful Session Bean (SessionSynchronization)

SessionSynchronization is the interface used for reporting messages, when you start or stop a transaction. According to the EJB specifications, you can specify Required, RequiresNew, or Mandatory in the transaction attributes of Stateful Session Beans in which SessionSynchronization is implemented. Correspondingly, you can specify Supports, NotSupported, and Never with Application Server.

This subsection describes the correspondence between the specified transaction attributes and availability of method invocation, and also the timing of invoking callback methods. The callback methods are:

afterBegin methods
afterBegin methods are either of the following methods:
  • Methods that implement the afterBegin method of the javax.ejb.SessionSynchronization interface
  • Methods in which @AfterBegin is specified

beforeCompletion methods
beforeCompletion methods are either of the following methods:
  • Methods that implement the beforeCompletion method of the javax.ejb.SessionSynchronization interface
  • Methods in which @BeforeCompletion is specified

afterCompletion methods
afterCompletion methods are either of the following methods:
  • Methods that implement the afterCompletion method of the javax.ejb.SessionSynchronization interface
  • Methods in which @AfterCompletion is specified

For details on using annotations, see 2.18 Specifications in Session Synchronization annotation.

(a) Transaction attributes and availability of method invocation

The following table describes the correspondence between transaction attributes of Stateful Session Beans in which SessionSynchronization is implemented and the availability of the invocation of business methods or callback methods.

Table 2-19 Availability of method invocation for business methods or callback methods

Transaction attribute Client transaction availability Business method invocation Invocation of callback method of SessionSynchronization
Supports Yes Y#1 Y#1
No Y#1 --
NotSupported Yes Y#1 --
No Y#1 --
Required Yes Y Y
No Y Y
RequiresNew Yes Y Y
No Y Y
Mandatory Yes Y Y
No --#2 --
Never Yes --#2 --
No Y#1 --

Legend:
Y: Method is invoked.
--: Method is not invoked.

#1
This operation is unique to Application Server.

#2
An exception, specified in the EJB specifications, is thrown.

(b) Timing of invoking callback methods

If the business method of the same Enterprise Bean is invoked more than once, the afterBegin method that is a callback method is invoked, when the Enterprise Bean first participates in the transaction.

The following is an example of invoking the afterBegin method. The following example shows the operation when a business method participating in a transaction is executed after executing the business method that does not participate in the transaction.

Figure 2-13 Example of invoking the callback method

[Figure]