Prev | Next

TOC | Index

J2EETM Developer's Guide
Transactions


Summary of Transaction Options

The decision tree in figure 6-2 shows the different approaches to transaction management that you may take. Your first choice depends on whether the enterprise bean is an entity or a session bean. An entity bean must use container-managed transactions. With container-managed transactions, you specify the transaction attributes in the deployment descriptor and you roll back a transaction with the setRollbackOnly method of the EJBContext interface. A session bean may have either container-managed or bean-managed transactions. There are two types of bean-managed transactions: JDBC and JTA transactions. You delimit JDBC transactions with the commit and rollback methods of the Connection interface. To demarcate JTA transactions, you invoke the begin, commit, and rollback methods of the UserTransaction interface.

In a session bean with bean-managed transactions, it is possible to mix JDBC and JTA transactions. This practice is not recommended, however, because it could make your code difficult to debug and maintain.

If you're unsure about how to set up transactions in an enterprise bean, here's a tip: In the deployment descriptor specify container-managed transactions. Then, set the Required transaction attribute for the entire bean. This approach will work most of the time.

FIGURE 6-2 Options in Specifying Transactions



Prev | Next

TOC | Index


Copyright © 2000 Sun Microsystems, Inc. All rights reserved.