Who Starts and Ends a Transaction?

In the EJB world, a transaction is typically associated with a session and not an entity bean. That is, entity beans don't have any control over when a transaction begins or ends, although an entity bean can signal that the transaction must be rolled back.

Session beans might or might not begin transactions on their own. You can specify that a session bean controls transactions on its own, in which case you must explicitly begin and end a transaction from within the various methods in your bean. When a session bean starts and ends transactions on its own, it's using Bean-Managed Transactions, or BMT.

A session bean can also let the container choose when to begin and end a transaction. You probably already guess ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.