Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
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:
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); } }
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").