Chapter 8. Transactions and containers
This chapter covers
In the previous chapter, we examined how to persist data, that is, make it durable. Yet, in several cases, this may not be enough. Not only do you need to make the enterprise data durable, but you may also need to make sure that either all of the data is persisted or none of the data is persisted. This all-or-nothing attribute is called atomicity and is achieved through the use of transactions.
Transactions are important to the enterprise, because enterprise applications generally involve several resources, and actions executed in these resources must be done in an atomic fashion. We’ll start our discussion by investigating a classic transaction use case where we need to transfer money between banking accounts.
Consider a banking application that transfers money from one account to another. Each account is implemented as database tables in an RDBMS (relational database management system). The banking application needs to debit one account and credit the other account by executing SQL (Structured Query Language) statements.
In chapter 7, you learned that one way of doing this is to use JDBC, as shown in the following listing.