In the EJBs deployment descriptor, the Bean Provider or Application Assembler In the EJBs deployment descriptor, the Bean Provider or Application Assembler Optionally, in the EJBs deployment descriptor, the Bean Provider or Application When a client appli

Introducing Transactions 2-5 Figure 2–1 How Transactions Work in a WebLogic Server EJB Application WebLogic Server supports two types of transactions in WebLogic Server EJB applications: ■ In container-managed transactions, the WebLogic Server EJB container manages the transaction demarcation. Transaction attributes in the EJB deployment descriptor determine how the WebLogic Server EJB container handles transactions with each method invocation. For more information about the deployment descriptor, see Implementing Enterprise Java Beans in Programming WebLogic Enterprise JavaBeans for Oracle WebLogic Server. ■ In bean-managed transactions, the EJB manages the transaction demarcation. The EJB makes explicit method invocations on the UserTransaction object to begin, commit, and roll back transactions. For more information, see weblogic.transaction.UserTransaction in the Oracle WebLogic Server API Reference. The sequence of transaction events differs between container-managed and bean-managed transactions.

2.3.1.1 Container-managed Transactions

For EJB applications with container-managed transactions, a basic transaction works in the following way:

1. In the EJBs deployment descriptor, the Bean Provider or Application Assembler

specifies the transaction type transaction-type element for container-managed demarcation Container.

2. In the EJBs deployment descriptor, the Bean Provider or Application Assembler

specifies the default transaction attribute trans-attribute element for the EJB, which is one of the following settings: NotSupported, Required, Supports , RequiresNew, Mandatory, or Never. For a detailed description of these settings, see Section 17.6.2 in the Enterprise JavaBeans Specification 2.0, published by Sun Microsystems, Inc.

3. Optionally, in the EJBs deployment descriptor, the Bean Provider or Application

Assembler specifies the trans-attribute for one or more methods.

4. When a client application invokes a method in the EJB, the EJB container checks

the trans-attribute setting in the deployment descriptor for that method. If no setting is specified for the method, the EJB uses the default trans-attribute setting for that EJB. 2-6 Programming JTA for Oracle WebLogic Server 5. The EJB container takes the appropriate action depending on the applicable trans-attribute setting. ■ For example, if the trans-attribute setting is Required, the EJB container invokes the method within the existing transaction context or, if the client called without a transaction context, the EJB container begins a new transaction before executing the method. ■ In another example, if the trans-attribute setting is Mandatory, the EJB container invokes the method within the existing transaction context. If the client called without a transaction context, the EJB container throws the javax.transaction.TransactionRequiredException exception. 6. During invocation of the business method, if it is determined that a rollback is required, the business method calls the EJBContext.setRollbackOnly method, which notifies the EJB container that the transaction is to be rolled back at the end of the method invocation. 7. At the end of the method execution and before the result is sent to the client, the EJB container completes the transaction, either by committing the transaction or rolling it back if the EJBContext.setRollbackOnly method was called.

2.3.1.2 Bean-managed Transactions