Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (

Part Number E13981-01
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Feedback page
Contact Us

Go to previous page
Go to next page
View PDF

Configuring an EJB 3.0 Transaction Attribute

To configure how the container manages transactions when a client invokes a method of an EJB 3.0 enterprise bean configured for container-managed transactions, you can use annotations (see Using Annotations) or deployment XML (see "Using Deployment XML").

For more information, see the following:

Using Annotations

You can configure transaction management using the @TransactionAttribute annotation attribute value, as Example 21-2 shows. Table 21-1 lists the TransactionAttributeType values you can specify and shows how the container will respond depending on whether or not a client-controlled transaction exists at the time the method is invoked.

Table 21-1 TransactionAttributeType Values for @TransactionAttribute

Transaction Attribute ClientEControlled Transaction Exists ClientEControlled Transaction Does Not Exist


Container suspends client transaction

Use no transaction


Use client-controlled transaction

Use no transaction


Use client-controlled transaction

Container starts a new transaction


Use client-controlled transaction

Container starts a new transaction


Use client-controlled transaction

Exception raised


Exception raised

Use no transaction

Footnote 1 Default.

You can apply the @TransactionAttribute annotation at the class-level to specify the default transaction attribute for all business methods of the enterprise bean. You can apply this annotation at the method-level to specify the transaction attribute for that method. Applying the annotation at the method-level overrides the class-level annotation (if any) for that method.

Example 21-2 Configuring Transaction Attribute for an EJB 3.0 Session Bean

import javax.ejb.Stateful;
import javax.annotation.PostConstruct;
import javax.ejb.Remove;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.ejb.TransactionAttribute;
import static javax.ejb.TransactionAttributeType.REQUIRED;
import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
import com.acme.Cart;

public class CartBean implements Cart {
    private ArrayList items;

    public void initialize() {
        items = new ArrayList();

    public void finishedShipping() {
        // Release any resources.

    public void addItem(String item) {

    public void removeItem(String item) {

Using Deployment XML

For an EJB 3.0 enterprise bean, you configure transaction attributes in the orion-ejb-jar.xml file as you would for an EJB 2.1 enterprise bean (see "Using Deployment XML").