Java Reference
In-Depth Information
In a Java EE application that uses the JMS API, you can use transactions to combine mes-
sage sends or receives with database updates and other resource manager operations. You
can access resources from multiple application components within a single transaction.
For example, a servlet can start a transaction, access multiple databases, invoke an enter-
prise bean that sends a JMS message, invoke another enterprise bean that modifies an EIS
system using the Connector architecture, and finally commit the transaction. Your applic-
ation cannot, however, both send a JMS message and receive a reply to it within the same
transaction; the restriction described in “ Using JMS API Local Transactions on page 366
still applies.
Distributed transactions within the EJB container can be either of two kinds:
Container-managed transactions : The EJB container controls the integrity of
your transactions without your having to call commit or rollback . Container-
managed transactions are recommended for Java EE applications that use the JMS
API. You can specify appropriate transaction attributes for your enterprise bean
methods.
Use the Required transaction attribute (the default) to ensure that a method is al-
ways part of a transaction. If a transaction is in progress when the method is called,
the method will be part of that transaction; if not, a new transaction will be started
before the method is called and will be committed when the method returns.
Bean-managed transactions : You can use these in conjunction with the
javax.transaction.UserTransaction interface, which provides its
own commit and rollback methods you can use to delimit transaction bound-
aries. Bean-managed transactions are recommended only for those who are exper-
ienced in programming transactions.
You can use either container-managed transactions or bean-managed transactions with
message-driven beans. To ensure that all messages are received and handled within the
context of a transaction, use container-managed transactions and use the Required
transaction attribute (the default) for the onMessage method. This means that if there is
no transaction in progress, a new transaction will be started before the method is called
and will be committed when the method returns.
When
you
use
container-managed
transactions,
you
can
call
the
following Mes-
sageDrivenContext methods:
setRollbackOnly : Use this method for error handling. If an exception occurs,
setRollbackOnly marks the current transaction so that the only possible out-
come of the transaction is a rollback.
Search WWH ::




Custom Search