title: Java EE Transactional Type across various types of Beans
body: <p>Consider the following scenario :</p>
  
  <p>Stateless Annotated Class ClassOne</p>
  
  <pre><code>@Stateless
  public class ClassOne {
      // some injected fields
      // ....
      @Inject
      private ClassTwo classTwo;
      // ....
  
      public void methodInClassOne() {
          try {
              classTwo.methodInClassTwo();
          } catch(Exception e) {
              // handle exception
          }
      }
  }
  </code></pre>
  
  <p>Stateless annotated Class ClassTwo</p>
  
  <pre><code>@Stateless
  public class ClassTwo {
      // some injected fields
      // ....
      @Inject
      private ClassThree classThree;
      // ....
  
      public void methodInClassTwo {
          try{
              classThree.methodInClassThree();
          } catch (Exception e) {
              // handle exception
          }
      }
  }
  </code></pre>
  
  <p>Non-annotated Class ClassThree</p>
  
  <pre><code>public class ClassThree {
      // some injected fields
      // ....
  
      public void methodInClassThree {
          // some business logic
          // ....
          if (conditionCheck) {
              throw new RuntimeException("error message");
          }
      }
  }
  </code></pre>
  
  <p>Say, for this case, the above <strong>conditionCheck</strong> always evaluates to <strong>true</strong>. This is a working code as of today. The RuntimeException is wrapped in an EjbException and caught, handled and rethrown as expected until it reaches ClassOne's catch block. But the moment I make ClassThree Stateless (with @Stateless), the RuntimeException caught up becomes an EjbTransactionRolledBackException causing the transaction to be Rolledback and any handling in ClassOne that tries to call a persist service blows up due to this.
  I tried experimenting with the @TransactionAttributes :</p>
  
  <ol>
  <li><p>SUPPORTS, REQUIRED -> gives the same RollBack behaviour killing the transaction</p></li>
  <li><p>NOT_SUPPORTED -> gives, even before the condition check, on a JpaRepository call a TransactionRequiredException (with which I assumed there should have been a TransactionType with the original non-annotated class as well. And probably not the same Transaction as in ClassTwo - due to point 1.)</p></li>
  <li><p>REQUIRES_NEW -> which seemed to behave as the original code behaved.</p></li>
  </ol>
  
  <p>I was under the impression that if nothing was explicitly stated then the invoked method/class would use the default type REQUIRED (which apparently wasn't the case because as mentioned in point 1.). So how does the TransactionType work between the Annotated(EJB)-NonAnnotated(CDI) beans? Is it different from how it works between two Annotated(EJB) beans? Im not sure if my question is clear. In short the whole Transaction behaviour is confusing, especially because of how it behaves differently for ClassThree before and after making it Stateless.</p>
  
  <p>Any inputs or reference to more informations on this would be really helpful. Thanks in advance</p>