An attempt by Holly to buy three boxes of chocolates
This obviously shouldn't work, because there's not enough credit left in Holly's
account. As expected, the web page reports that there was an issue and that the pur-
chase wasn't successful (figure 3.16).
Looking at the web page more closely, though, it becomes clear that something is
terribly wrong. The account wasn't debited, but the chocolates were still taken out of
the stock. Holly is happy, but giving away chocolates to people with inadequate credit
ratings isn't a sound way to run a business.
MAKING THE SHOP ROBUST
The core of the problem is the granularity of the transactions. The container-
managed JTA is helpfully wrapping every method call to InventoryImpl or Account-
ingImpl in a transaction, and any failure in those methods will cause the transaction
to be rolled back (figure 3.17). As you saw earlier, if a new customer doesn't have a
Figure 3.16 If a user tries to buy something that exceeds their credit limit, the purchase doesn't
succeed and their account isn't debited. Unfortunately, the stock levels are reduced.
Search WWH ::