uCosminexus Application Server, EJB Container Functionality Guide

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

2.18.1 Method of setting Session Synchronization with annotation

When a transaction is managed in CMT, transactions are managed by the container. In such cases, you can develop an application without implementing start and end of the transaction. In the management by a container, the transaction starts immediately before the start of the method and it is committed and ended immediately after the end of the method.

If you want to execute a specific processing before and after the start and end of a transaction by the container, use the Session Synchronization functionality. You can use the Session Synchronization functionality in either of the following methods:

You can use the method that specifies the annotation in EJB3.1 or later. If you specify annotations, you can set the timing of executing the process before and after the start and end of a transaction without implementing the javax.ejb.SessionSynchronization interface. This simplifies the development of the application.

This subsection describes the specifications when annotations are to be used. You can use the following annotations:

@AfterBegin
@AfterBegin is an annotation which reports the start of a new transaction. A container invokes the processing with the specification of this annotation after the start of the transaction and immediately before invoking the business method.

@BeforeCompletion
@BeforeCompletion is an annotation which reports the completion of the business method. The processing with the specification of this annotation is invoked after completing the business method and immediately before committing the transaction. If you want to roll back the processing implemented by the business method, you must invoke the setRollbackOnly method at this time.

@AfterCompletion
@AfterCompletion is an annotation which reports the completion of a transaction. The processing with the specification of this annotation is invoked immediately after completion of the transaction.
In this annotation, you can specify true or false as a parameter. If you specify true, processing is executed when the transaction is committed. If you specify false, processing is executed when the transaction is rolled back.

You can specify these annotations in the class of a Stateful Session Bean (or its parent class). With respective Session Beans, you can specify one of these annotations for each type.