Chapter 16. Transactions

Transactions and transactional support are crucial for most J2EE applications. J2EE provides thorough and solid support for transactions in the form of JTA. This chapter begins with a brief overview of transaction terminology, including ACID properties and transaction isolation levels as well as the concepts of local and distributed transactions. It then describes various distributed transaction scenarios, such as reading a message from a queue and updating information in a database table within a single transaction. The chapter covers the programmatic transaction model provided by the JTA but also describes the declarative transaction model used with J2EE components.

Transaction support is an essential part of many Java and J2EE APIs such as JDBC and JMS. This chapter covers core concepts about transactions, but you’ll find more detailed information about JDBC and JMS in Chapters 8 and 11, respectively. Since EJBs, described in Chapter 6, represent the standard persistence model for J2EE, EJBs have extensive support for JTA-based transactions. Hibernate, the open source persistence API discussed in Chapter 20, also provides support for JTA-based transactions.

Transaction Overview

Before delving into the details of how transactions work, let’s define some basic terminology. A transaction is a unit of work, a sequence of operations that succeed or fail as a single unit. Transactions guarantee that this unit of work either fully completes or is fully rolled back. ...

Get Java Enterprise in a Nutshell, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.