How attributes work
Mark a method with one of six transaction attributes:
Required
RequiresNew
Mandatory
Supports
NotSupported
Never

When the method is called, the container uses the attribute to do one of five things:
Run the method in the caller’s transaction.
OR
Suspend the caller’s transaction and start a new transaction.
OR
Suspend the caller’s transaction and run the method without a transaction.
OR
Throw an exception because the caller does not have a transaction.
OR
Throw an exception because the caller does have a transaction.
void go() { aFooBean.setFoo(); }

Know your attributes
How an attribute affects behavior depends on one thing:
Is the calling method in a transaction?

Method foo() is in a transaction (tx A).

Method bar() is marked with the Required transaction attribute.
<method> <ejb-name>MyBean</ejb-name> <method-name>bar</method-name> </method> <trans-attribute>Required</trans-attribute>
Note
The bar() method runs in the same transaction as foo() because bar() is marked Required and foo() has a ...
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