How it works in EJB
Transactions can propagate through method calls
When a bean is running code in a transaction, and calls a method on another bean, three different scenarios are possible:
The called method runs in the caller’s transaction.
The called method runs without a transaction.
The called method runs within its own new transaction.
The transaction started in the first method propagates to all other methods in the call stack. All called methods run within the same transaction. (In this book, we’ll abbreviate “transaction” to “tx”.)

So, what does it mean for multiple methods to run in the same transaction context? That depends on the bean type and what the beans do in their code. For example, imagine Bean A has a method with JDBC code that does an update to a database row. If any other method in the same transaction causes a rollback, Bean A’s update won’t commit, even if the database would have been more than happy to do it.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access