EJB Transactional Attributes

This page discusses - EJB Transactional Attributes

Ads

Tutorials   
Chapter 5. Client View of an Entity Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements related to transactions and the identifica Given a list of responsibilities, identify whose which are the Container's with respect to transactions, including the handling of getRollbackOnly, setRollbackOnly, getUserTransacti EJB Transactional Attributes Chapter 11. Transactions Given a list of scenarios, identify which will result in an ejbRemove method not being called on a bean instance. Given a list of responsibilities related to session beans, identify those which are the responsibility of the session bean provider and those which are the responsibility of the EJB contai Given a list of methods for a stateful or stateless session bean class, define which of the following operations can be performed from each of those methods: SessionContext interface metho Chapter 4. Session Bean Life Cycle Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces. Identify the interface and method for each of the following: retrieve the session bean's remote home interface, retrieve the session bean's local component interface, determine if the sessio Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both. Chapter 14. Security Management Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag. Given a list of responsibilities, identify which belong to the deployer, bean provider, application assembler, container provider, system administrator, or any combination. From a list of responsibilities, identify which belong to the application assembler, bean provider, deployer, container provider, or system administrator. Part I. Exam Objectives Preface Identify the interfaces and methods a JMS message-driven bean must implement. Identify the use and behavior of the MessageDrivenContext interface methods. SCBCD Study Guide Given a list of responsibilities related to exceptions, identify those which are the bean provider's, and those which are the responsibility of the container provider. Be prepared to recog Given a particular method condition, identify the following: whether an exception will be thrown, the type of exception thrown, the container's action, and the client's view. Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans. Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation. Identify correct and incorrect statements or examples about an entity bean's primary key and object identity. Identify the use, syntax, and behavior of, the following entity bean home method types, for Container-Managed Persistence (CMP); finder methods, create methods, remove methods, and home me Chapter 8. Entity Beans Chapter 13. Enterprise Bean Environment Chapter 2. Client View of a Session Bean Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information. Given a list, identify which are requirements for an EJB-jar file. Identify correct and incorrect statements or examples about the client view of a entity bean's remote component interface (EJBObject). Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions. Identify correct and incorrect statements or examples about the purpose and use of EJB QL. Chapter 9. EJB-QL Identify correct and incorrect statements or examples about EJB programming restrictions. Chapter 1. EJB Overview Identify EJB 2.0 container requirements. Identify correct and incorrect statements or examples about the client view of an entity bean's local component interface (EJBLocalObject).

Given a list of transaction behaviors, match them with the appropriate transaction attributes.

A transaction attribute is a value associated with a method of a session or entity bean's home or component interface or with the onMessage(...) method of a message-driven bean. The transaction attribute specifies how the Container must manage transactions for a method when a client invokes the method via the enterprise bean's home or component interface or when the method is invoked as the result of the arrival of a JMS message.

The transaction attribute must be specified for the following methods:

  • For a SESSION bean, the transaction attributes MUST be specified for the methods defined in the bean's COMPONENT interface and all the direct and indirect superinterfaces of the component interface, excluding the methods of the javax.ejb.EJBObject or javax.ejb.EJBLocalObject interface. Transaction attributes MUST NOT be specified for the methods of a session bean's HOME interface.

  • For an ENTITY bean, the transaction attributes MUST be specified for the methods defined in the bean's COMPONENT interface and all the direct and indirect superinterfaces of the component interface, excluding the getEJBHome, getEJBLocalHome, getHandle, getPrimaryKey, and isIdentical methods; and for the methods defined in the bean's HOME interface and all the direct and indirect superinterfaces of the home interface, excluding the getEJBMetaData and getHomeHandle methods specific to the remote home interface (remove, create, and find methods can all have transaction attributes).

  • For a MESSAGE-DRIVEN bean, the transaction attribute MUST be specified for the bean's onMessage(...) method.

Providing the transaction attributes for an enterprise bean is an optional requirement for the Application Assembler, because, for a given enterprise bean, the Application Assembler must either specify a value of the transaction attribute for all the methods for which a transaction attribute must be specified, or the Assembler must specify none. If the transaction attributes are not specified for the methods of an enterprise bean, the Deployer will have to specify them.

Enterprise JavaBeans defines the following (SIX) values for the transaction attribute:

  • NotSupported

  • Required

  • Supports

  • RequiresNew

  • Mandatory

  • Never

For MESSAGE-DRIVEN beans, ONLY the Required and NotSupported transaction attributes may be used.

For ENTITY beans that use EJB 2.0 container-managed persistence, only the Required, RequiresNew, or Mandatory transaction attributes should be used for the methods defined in the bean's component interface and all the direct and indirect superinterfaces of the component interface, excluding the getEJBHome, getEJBLocalHome, getHandle, getPrimaryKey, and isIdentical methods; and for the methods defined in the bean's home interface and all the direct and indirect superinterfaces of the home interface, excluding the getEJBMetaData and getHomeHandle methods specific to the remote home interface. Containers may optionally support the use of the NotSupported, Supports, and Never transaction attributes for the methods of entity beans with container-managed persistence. However, entity beans with container-managed persistence that use these transaction attributes WILL NOT BE PORTABLE.

If an enterprise bean implements the javax.ejb.SessionSynchronization interface, the Application Assembler can specify only the following values for the transaction attributes of the bean's methods: Required, RequiresNew, or Mandatory. This restriction is necessary to ensure that the enterprise bean is invoked only in a transaction. If the bean were invoked without a transaction, the Container would not be able to send the transaction synchronization calls.

Container-managed transaction demarcation for Session and Entity Beans.

  • NotSupported

    The Container invokes an enterprise Bean method whose transaction attribute is set to NotSupported 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.

  • Required

    The Container must invoke an enterprise Bean method whose transaction attribute is set to Required 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.

  • 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 (uses client's transaction).

    • If the client calls without a transaction context, the Container performs the same steps as described in the NotSupported case (with an unspecified transaction context).

  • RequiresNew

    The Container must invoke an enterprise Bean method whose transaction attribute is set to RequiresNew 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.

  • 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 (uses client's transaction).

    • If the client calls without a transaction context, 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.

  • 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 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 NotSupported case (with an unspecified transaction context).

Container-managed transaction demarcation for Message-driven Beans.

Only the NotSupported and Required transaction attributes may be used for message-driven beans. The use of the other transaction attributes is not meaningful for message-driven beans because there can be no pre-existing transaction context (RequiresNew, Supports) and no client to handle exceptions (Mandatory, Never).

  • NotSupported

    The Container invokes a message-driven Bean method whose transaction attribute is set to NotSupported with an unspecified transaction context.

    If the onMessage(...) method invokes other enterprise beans, the Container passes NO transaction context with the invocation.

  • Required

    The Container must invoke a message-driven Bean method whose transaction attribute is set to Required with a valid transaction context. Because there is never a client transaction context available for a message-driven bean, the container automatically starts a new transaction before the dequeuing of the JMS message and, hence, before the invocation of the message-driven bean's onMessage(...) method. The Container automatically enlists the resource manager associated with the arriving message and all the resource managers accessed by the onMessage(...) method with the transaction. If the onMessage(...) method invokes other enterprise beans, the Container passes the transaction context with the invocation. The Container ATTEMPTS TO COMMIT the transaction when the onMessage(...) method has completed. If the onMessage(...) method does not successfully complete or the transaction is rolled back by the Container, JMS message redelivery semantics apply.

Table 11.1. Transaction attribute summary

Transaction attributeClient's transactionTransaction associated with business methodTransaction associated with resource managers
NotSupportednonenonenone
T1nonenone
RequirednoneT2T2
T1T1T1
Supportsnonenonenone
T1T1T1
RequiresNewnoneT2T2
T1T2T2
MandatorynoneERRORn/a
T1T1T1
Nevernonenonenone
T1ERRORn/a

Advertisements

Share on Google+Share on Google+

EJB Transactional Attributes

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: EJB Transactional Attributes  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads