Transactions are central to any enterprise application.
Transaction management in J2EE applications is traditionally associated with EJB. Container Managed Transactions (CMT) is the most compelling value proposition of Stateless Session Beans (SLSBs). Many J2EE applications use local SLSBs purely for transaction demarcation, needing no other EJB services.
This chapter will take a fresh look at transaction strategies. We'll see that EJB is just one way of managing transactions in J2EE applications, and that there are simpler alternatives that are more appropriate for many applications.
We'll look at JTA, the core J2EE API that EJB CMT serves to access, and how we can leverage JTA without EJB. We'll also consider whether JTA is always appropriate, and when local (resource-specific) transactions are appropriate.
We'll consider transaction management with popular O/R mapping tools such as JDO and Hibernate, and re-examine some common but questionable assumptions of J2EE orthodoxy, such as the belief that applications commonly use more than one transactional resource. We'll try to approach transaction management—often considered a dark art—through the values of simplicity, productivity, and object orientation that we've discussed in previous chapters.
This chapter doesn't define transactions, isolation levels, ACID characteristics, or other basic concepts. Please see, for example, Chapter 5 ("Concurrency") of Martin Fowler's Patterns of Enterprise Application ...