Transactions in enterprise beans
As we mentioned earlier in this chapter, by default, all enterprise bean methods are automatically wrapped in a transaction. This default behavior is known as container-managed transactions, since transactions are managed by the Jakarta EE runtime. Application developers may also choose to manage transactions themselves. This can be accomplished by using bean-managed transactions. Both of these approaches are discussed in the following sections.
Container-managed transactions
Because enterprise bean methods are transactional by default, we run into an interesting dilemma when an enterprise bean method is invoked from client code that is already in a transaction. How should the Jakarta EE runtime behave? Should it suspend the client transaction, execute its method in a new transaction, and then resume the client transaction? Should it not create a new transaction and execute its method as part of the client transaction? Should it throw an exception...