In this section, we’ll look at some of the most common transaction scenarios and we’ll examine ways to leverage transactions effectively.
The subsection “Using a Session Façade” provides a concrete example of how to use CMTD effectively with an EJB component by minimizing the number of unnecessary transactions and increasing performance.
The subsection “Using Transaction Attributes with CMTD” illustrates an approach for utilizing transaction attributes with CMTD EJBs. This approach can help avoid resorting to BMTD in some situations.
The subsection “Distributed Transactions Involving a JMS Destination and Database” provides a detailed example of a distributed transaction using both JMS and JDBC resources.
Consider the code fragment in Example 16-3, which uses a
Person EJB component. Assume that
the EJB has been deployed using the
Required transaction attribute applied to
all of its methods. How many transactions does the user invoke in
total? The answer is four. Each EJB method,
getPersonId(), is invoked in a different
transaction. This is most likely not the intended behavior. This
code is not only very expensive but also may be incorrect. For
example, if there is some error setting the home phone number, the
client might expect the creation of a person bean instance to
Example 16-3. Direct usage
PersonHome aPersonHome = (PersonHome) aInitialContext.lookup("java:comp/env/ejb/Person"); ...