Reputation: 29703
Let's I have Stateless
bean with CMT. I have 3 methods in bean, 2 with TransactionAttributeType.REQUIRED
. And both method are called from third method. How can I check when transaction is active? i want check
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MyBean
{
public RetType methodA()
{
methodB();
//.... is CMT active there?
methodC();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public RetType methodB(){}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public RetType methodC(){}
}
Upvotes: 0
Views: 151
Reputation: 4211
The TransactionAttributeType.REQUIRED
attribute is the default for container managed transactions bean methods, so even if you didn't annotate it, methodA
runs in a transaction that starts as soon as the method starts (unless you call the method from another active transaction, in that case the method simply join the current transaction).
The transaction ends when the method upon method exit (again unless called from another transaction). Any method called by methodA
, unless annotated with TransactionAttributeType.REQUIRES_NEW
, joins the current transaction.
Upvotes: 3