O'Reilly logo

Hibernate Recipes: A Problem-Solution Approach by GARY MAK, SRINIVAS GURUZU

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. Transactions and Concurrency

Let's say a buyer logs in to the bookshop application and purchases a book. The following actions should take place in the event of 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. That means either both actions should be successfully completed, or they should have no effect. These actions collectively are called a transaction or unit of work. In essence, transactions provide an all-or-nothing proposition.

The concept of transactions is inherited from database management systems. By definition, a transaction must be atomic, consistent, isolated, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required