Download
FAQ History |
API
Search Feedback |
Summary of Transaction Options for Enterprise Beans
If you're unsure about how to set up transactions in an enterprise bean, here's a tip: In the bean's deployment descriptor, specify container-managed transactions. Then set the
Required
transaction attribute for the entire bean. This approach will work most of the time.Table 30-2 lists the types of transactions that are allowed for the different types of enterprise beans. 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 by calling the
setRollbackOnly
method of theEJBContext
interface or when a system-level exception is thrown.
Table 30-2 Allowed Transaction Types for Enterprise Beans Bean Type Container-Managed Bean-Managed JTA JDBC Entity Y N N Session Y Y Y Message-driven Y Y Y
A session bean can have either container-managed or bean-managed transactions. There are two types of bean-managed transactions: JDBC and JTA transactions. You delimit JDBC transactions using the
commit
androllback
methods of theConnection
interface. To demarcate JTA transactions, you invoke thebegin
,commit
, androllback
methods of theUserTransaction
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 can make your code difficult to debug and maintain.
Like a session bean, a message-driven bean can have either container-managed or bean-managed transactions.
Download
FAQ History |
API
Search Feedback |
All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.