0

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(){}
}
4

1 回答 1

3

TransactionAttributeType.REQUIRED属性是容器管理事务 bean 方法的默认属性,因此即使您没有对其进行注释,它也会methodA在方法启动后立即启动的事务中运行(除非您从另一个活动事务调用该方法,在这种情况下该方法只需加入当前交易)。
当方法退出时,事务结束(再次除非从另一个事务调用)。由 调用的任何方法methodA,除非用 注释,否则TransactionAttributeType.REQUIRES_NEW将加入当前事务。

于 2012-12-04T15:03:54.430 回答