CHAPTER 13
Transactions and Concurrency
Let’s say that a buyer logs in to the bookshop application and purchases a book. The following actions should take place in the event of a purchase:
- Charge the buyer the cost of the book
- Reduce the stock of the book
If the charge on the credit card fails, the stock shouldn’t be reduced. Also, when the book is out of stock, the buyer shouldn’t be charged. So both actions should be successfully completed or else they should have no effect. These actions collectively are called transactions or units of work. In essence, transactions provide an all-or-nothing proposition.
The concept of transactions is inherited ...
Get Hibernate Recipes: A Problem-Solution Approach, Second 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.