Occasionally, there is a need for a stateful Session bean to have visibility as to the progress of the underlying transaction. Specifically, a bean might need to know
Has the transaction started?
Is the transaction about to complete?
Did the transaction complete successfully or was it rolled back?
For example, consider the age-old example of a ShoppingCart bean. In its purchase() method, it is likely to modify its internal state. Perhaps it holds its contents in a java.util.List called currentContents. On purchase(), it might move the contents of currentContents to another java.util.List called recentlyBought.
Suppose, then, that the transaction that actually modifies the persistent data store fails to complete. ...