uCosminexus Application Server, EJB Container Functionality Guide
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:
The behavior of transaction attributes is explained in the figures below, for each type of transaction 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
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
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
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
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
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
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 |
Stateful Session Bean (SessionSynchronization) |
|
Required |
Singleton Session Bean (Except PostConstruct/PreDestroy) #1 |
|
Required |
Entity Bean (CMP 2.0) |
|
Required |
Message-driven Bean (when using a resource adapter in compliance with Connector 1.0) |
|
Required |
Message-driven Bean (when using a resource adapter in compliance with Connector 1.5) |
|
Required#2 |
Session Bean without a DD using annotations |
|
Required |
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:
For details on using annotations, see 2.18 Specifications in Session Synchronization annotation.
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 | -- |
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
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.