Name

SessionSynchronization

Synopsis

Session beans are not required to be transactional, but if you want your session bean to be notified of transaction boundaries, you can have your bean implementation class extend the SessionSynchronization interface. The EJB container will invoke the methods on this interface to notify your bean about the start and end of transactions.

The afterBegin() is called when a new transaction has started. Any business methods invoked on the bean between this point and a subsequent call to its beforeCompletion() method, will execute within the context of this transaction. The beforeCompletion() method is called on the bean when a transaction is about to end. The afterCompletion() method is called after the transaction has ended, and the boolean argument tells the bean whether the transaction was committed successfully (true), or rolled back (false).

public interface SessionSynchronization {
// Public Instance Methods
   public abstract void afterBegin(
        ) throws EJBExceptionjava.rmi.RemoteException;  
   public abstract void afterCompletion(
        boolean committed) throws EJBExceptionjava.rmi.RemoteException;  
   public abstract void beforeCompletion(
        ) throws EJBExceptionjava.rmi.RemoteException;  
}

Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.