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(){}
}
The
TransactionAttributeType.REQUIREDattribute is the default for container managed transactions bean methods, so even if you didn’t annotate it,methodAruns 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 withTransactionAttributeType.REQUIRES_NEW, joins the current transaction.