Container-managed transactions
Now that we’ve looked at the do-it-yourself way to demarcate transactions, you’ll see how easy it is with CMT. So easy that you don’t write anything transactional in your code except maybe an occasional call to EJBContext.setRollbackOnly() or EJBContext.getRollbackOnly().

With CMT, transactions are started and completed (with either a commit or rollback) by the container, based solely on the deployment descriptor. You (OK, technically the Application Assembler) mark some attributes in the deployment descriptor and that’s it.
Almost.
Unless you understand exactly what the six transaction attributes are, and the implications of how different attributes interact at runtime, you won’t have a clue about whether your bean is even going to be in a transaction. Or, how big the transaction will be. Or, whether you’ve created a dangerous situation that could blowup at runtime.
Fortunately, there are only six. And the rules for how the container behaves with each of those attributes is very clear and simple.
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