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

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

Go to previous page
Previous
Go to next page
Next
View PDF

Configuring EJB 3.0 Transaction Management

To configure EJB 3.0 EJB transaction management, you can use annotations (see "Using Annotations") or deployment XML (see "Using Deployment XML").


Note:

EJB 3.0 entities cannot be configured with a transaction management type. EJB 3.0 entities execute within the transactional context of the caller.

For more information, see the following:

Using Annotations

You can configure transaction management using the @TransactionManagement annotation attribute value, as Example 21-1 shows. You can specify one of the following values:

  • TransactionManagementType.CONTAINER: container-managed transactions (default).

  • TransactionManagementType.BEAN: bean-managed transactions.

You apply the @TransactionManagement annotation at the class level.

Example 21-1 Configuring Transaction Management 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;

@Stateful
@TransactionManagement(value=TransactionManagementType.CONTAINER)
public class CartBean implements Cart {
    private ArrayList items;

    @PostConstruct
    public void initialize() {
        items = new ArrayList();
    }

    @Remove
    public void finishedShipping() {
        // Release any resources.
    }

    public void addItem(String item) {
        items.add(item);
    }

    public void removeItem(String item) {
        items.remove(item);
    }
}

Using Deployment XML

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