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 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").


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;

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 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").