Java Reference
In-Depth Information
lowing listing. The bean first checks to see if there are any bids on the item, and if there are
none, it validates the customer's credit card, charges the customer, and removes the item
from bidding. To keep the code sample as simple as possible, most of the business logic is
Listing 6.1. Implementing snag-it ordering using CMT
First, you tell the container that it should manage the transactions for this bean . This is
optional for this bean because the container assumes CMT by default. The EJB context is
injected into the bean . A transaction is required for the placeSnagItOrder meth-
od , and the container should start one when needed. If an exception stops you from
completing the snag-it order, you ask the container to roll back the transaction using the
injected EJBContext object's setRollbackOnly method . It's your responsibility
to roll back the exception in the event of an application error. Let's take a closer look at the
TransactionManagement annotation.
Search WWH ::

Custom Search