2

We have two EJB session beans as given below;

@Stateless
public class MyStatelessSessionBean{
      @EJB
       MyStatefulSessionBean statefulBean;
      public void methodA(){
          statefulBea.methodB();
      }
}

@Stateful
@ TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MyStatefulSessionBean {
     @Asynchronous
     public void methodB(){
     }

}

A client, which is not in any in any transaction, invoke methodA of MyStatelessSessionBean. How many distict transactions will be started by container after all processing has completed ?

sauumum
  • 1,638
  • 1
  • 19
  • 36
  • **As per my understanding, 2 transaction will be started by EJB container.** _As client invoke methodA of MyStatelessSessionBean without any active transaction, container will start a new transaction for methodA as by default all methods are annotated with TransactionAttributeType.REQUIRED. When asynchronous methodB, which is marked as TransactionAttributeType.REQUIRED, is invoked, container will again start a new transaction._ – sauumum Jan 03 '15 at 18:53

1 Answers1

3

There will be 2 transactions started. As EJB 3.1 specification states in point 4.5.3:

Client transaction context does not propagate with an asynchronous method invocation. From the Bean Developer’s view, there is never a transaction context flowing in from the client. This means, for example, that the semantics of the REQUIRED transaction attribute on an asynchronous method are exactly the same as REQUIRES_NEW.

slwk
  • 587
  • 3
  • 7