Container-Managed Transaction Demarcation for Session and Entity Beans

ejb-3_0-fr-spec-ejbcore

13.6.2 Container-Managed Transaction Demarcation for Session and Entity Beans

13.6.2.1 NOT_SUPPORTED

The container invokes an enterprise bean method whose transaction attribute is set to the NOT_SUPPORTED value with an unspecified transaction context.

If a client calls with a transaction context, the container suspends the association of the transaction context with the current thread before invoking the enterprise bean’s business method.

The container resumes the suspended association when the business method has completed. The suspended transaction context of the client is not passed to the resource managers or other enterprise bean objects that are invoked from the business method. If the business method invokes other enterprise beans, the container passes no transaction context with the invocation.

Refer to Subsection 13.6.5 for more details of how the container can implement this case.

13.6.2.2 REQUIRED

The container must invoke an enterprise bean method whose transaction attribute is set to the REQUIRED value with a valid transaction context.

If a client invokes the enterprise bean’s method while the client is associated with a transaction context, the container invokes the enterprise bean’s method in the client’s transaction context.

If the client invokes the enterprise bean’s method while the client is not associated with a transaction context, the container automatically starts a new transaction before delegating a method call to the enterprise bean business method. The container automatically enlists all the resource managers accessed by the business method with the transaction. If the business method invokes other enterprise beans, the container passes the transaction context with the invocation. The container attempts to commit the transaction when the business method has completed. The container performs the commit protocol before the method result is sent to the client.

13.6.2.3 SUPPORTS

The container invokes an enterprise bean method whose transaction attribute is set to SUPPORTS as follows.

  • If the client calls with a transaction context, the container performs the same steps as described in the REQUIRED case.
  • If the client calls without a transaction context, the container performs the same steps as described in the NOT_SUPPORTED case.
  • The SUPPORTS transaction attribute must be used with caution. This is because of the different transactional semantics provided by the two possible modes of execution. Only the enterprise beans that will execute correctly in both modes should use the SUPPORTS transaction attribute.

    13.6.2.4 REQUIRES_NEW

    The container must invoke an enterprise bean method whose transaction attribute is set to REQUIRES_NEW with a new transaction context.

    If the client invokes the enterprise bean’s method while the client is not associated with a transaction context, the container automatically starts a new transaction before delegating a method call to the enterprise bean business method. The container automatically enlists all the resource managers accessed by the business method with the transaction. If the business method invokes other enterprise beans, the container passes the transaction context with the invocation. The container attempts to commit the transaction when the business method has completed. The container performs the commit protocol before the method result is sent to the client.

    If a client calls with a transaction context, the container suspends the association of the transaction context with the current thread before starting the new transaction and invoking the business method. The container resumes the suspended transaction association after the business method and the new transaction have been completed.

    13.6.2.5 MANDATORY

    The container must invoke an enterprise bean method whose transaction attribute is set to MANDATORY in a client’s transaction context. The client is required to call with a transaction context.

  • If the client calls with a transaction context, the container performs the same steps as described in the REQUIRED case.
  • If the client calls without a transaction context, the container throws the javax.ejb.EJBTransactionRequiredException[69]. If the EJB 2.1 client view is used, the container throws the javax.transaction.TransactionRequiredException exception if the client is a remote client, or the javax.ejb.TransactionRequiredLocalException if the client is a local client.
  • 13.6.2.6 NEVER

    The container invokes an enterprise bean method whose transaction attribute is set to NEVER without a transaction context defined by the EJB specification. The client is required to call without a transaction context.

  • If the client calls with a transaction context, the container throws the javax.ejb.EJBException[ 70]. If the EJB 2.1 client view is used, the container throws the java.rmi.RemoteException exception if the client is a remote client, or the javax.ejb.EJBException if the client is a local client.
  • If the client calls without a transaction context, the container performs the same steps as described in the NOT_SUPPORTED case.
  • Advertisements

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s