title: @Singleton bean failed to initialize because of not expected transaction status 4 when it's marked TransactionAttribute=NOT_SUPPORTED
body: <p>I'm having difficulty with my EJB3.1 bean initialisation and more specifically to do with it failing due to perceived transaction rollback, even though I've marked the bean with <code>@TransactionAttribute(NOT_SUPPORTED)</code>. This should mean that any client transaction is paused on bean method entry until exit (when it will be resumed. It's definitely the transactional apprach I want. </p>
  
  <p>The "gist" of the code and error are as follows (note some of it is hand-cranked to hide details but is all relevant and representative):</p>
  
  <pre><code>@Singleton(name = "MyClass")
  @ConcurrencyManagement(value = BEAN)
  @TransactionAttribute(value = NOT_SUPPORTED)
  @Local(MyInterface.class)
  public class MyClass implements MyInterface {
  
      @PostConstruct
      public void init() throws MyException {
          try {
              ...
          } catch LowerLevelException e) {
              throw new MyException("problem", e);
          }
      }
  
      public Object doSomething(...) throws MyException {
          ...
      }
      ...
  }
  </code></pre>
  
  <p>This raises the following error:</p>
  
  <pre><code>javax.ejb.NoSuchEJBException: Singleton MyClass(Application: my-ear, EJBComponent: my-ejb.jar) failed to initialize.
  </code></pre>
  
  <p>which, when I debug is actually wrapping the following exception:</p>
  
  <pre><code>weblogic.ejb.container.InternalException: Transaction marked rollback or not expected transaction status: 4
  </code></pre>
  
  <p>Again, debugging raises some interesting details:</p>
  
  <ol>
  <li>Firstly, my <code>MyClass#init</code> is being executed completely and successfully without any issues/ exceptions.</li>
  <li>The  <code>#init</code> is being called on first call to my <code>#doSomething</code> method from client code (as part of post-construct).</li>
  <li>So, there are reams of levels of stack-indirection between the client-call to <code>MyClass#doSomething</code> down to <code>#init</code> and the exception is raised inside of one of these layers. It's raised in WLS Singleton session bean management code. See below...</li>
  </ol>
  
  <p>The stack resembles that below (MyClass names changed):</p>
  
  <pre><code>MyClass_fefgu8_Impl(MyClass).init() line: 96              
  NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]        
  NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57    
  DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43            
  Method.invoke(Object, Object...) line: 601          
  Jsr250Metadata.invokeLifecycleMethod(Object, Method, Object[]) line: 393      
  InterceptionMetadata(Jsr250Metadata).invokeLifecycleMethods(Object, LifecycleEvent) line: 365          
  InterceptionMetadata.invokeLifecycleMethods(Object, LifecycleEvent) line: 403              
  EjbComponentCreatorImpl.invokePostConstruct(Object, String) line: 80               
  SingletonSessionManager.constructAndInitBean() line: 369         
  SingletonSessionManager.access$300(SingletonSessionManager) line: 63            
  SingletonSessionManager$SingletonLifecycleManager.doActualInit() line: 798    &lt;== InternalException raised here
  SingletonSessionManager$SingletonLifecycleManager.initInternal(boolean) line: 744     
  SingletonSessionManager$SingletonLifecycleManager.getBean() line: 648           
  SingletonSessionManager.getBeanFor(InvocationWrapper) line: 285      
  SingletonSessionManager.preInvoke(InvocationWrapper) line: 147         
  SingletonLocalObject(BaseLocalObject).getBeanInstance(InvocationWrapper) line: 146 
  SingletonLocalObject(BaseLocalObject).preInvoke(InvocationWrapper, ContextHandler, boolean, boolean) line: 103         
  SingletonLocalObject(BaseLocalObject).__WL_preInvoke(InvocationWrapper, ContextHandler) line: 67               
  SessionLocalMethodInvoker.invoke(Invokable, BaseLocalObject, InvocationWrapper, Object[], int) line: 20        
  MyClass_fefgu8_MyInterfaceImpl.doSomething(String, String, String, String) line: not available
  </code></pre>
  
  <p>And the Transaction rollback exception is actually raised in stack-frame:</p>
  
  <pre><code>SingletonSessionManager$SingletonLifecycleManager.doActualInit() line: 798   
  </code></pre>
  
  <p>This level does have dealing with a transaction manager but I've no idea why it should be trying to mark a transaction for rollback, especially after a successful init from the main application code.</p>
  
  <p>I'm using this EJB component to compile this bean but we use WLS EJB code on the server (or course):</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.glassfish&lt;/groupId&gt;
      &lt;artifactId&gt;javax.ejb&lt;/artifactId&gt;
      &lt;version&gt;3.1&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>The reason I've put this out there is that it's proving tricky, there's precious little on-line (especially with transaction status 4), I've spent a bit too long on it and need to move on.  I'm carrying on looking but I thought I might get more leads for when I'm back on Monday.</p>
  
  <p>I've re-read a lot around EJB transaction handling and don't see any obvious issues. I believe I'm using the correct mechanism for handling the transaction in my bean (i.e. it's non-transactional). I've not yet tried putting it in the descriptor instead (which I just thought of and will give a go). I've also not yet delved deeply into how<code>SingletonSessionManager$SingletonLifecycleManager.doActualInit</code> works but there's not a lot on-line about it.</p>
  
  <p><strong>The question</strong></p>
  
  <p>To rephrase, the question is... 
   - What am I missing so that my bean methods are not participating in any supplied transaction, or more specifically, not trying to mark a transaction for rollback? 
   - Why should it fail to initialise with this error if I've explicitly told it not to "support" (care about) any transactions?</p>
  
  <p>N.B. I've checked this <a href="https://stackoverflow.com/q/12621559/758831">@Singleton bean failed to initialize because of not expected transaction status 1 </a> issue but my scenario doesn't relate to Java EE security role permissions (I don't think!)</p>
  
  <p>Thanks.</p>
  
  <p><strong>Update 1</strong></p>
  
  <p>Well, the latest is that removing my <code>@TransactionAttribute</code> annotation seems to get me past the failure. This is strange though as the default should be <a href="http://docs.oracle.com/javaee/6/api/javax/ejb/TransactionAttribute.html" rel="nofollow noreferrer">TransactionAttributeType#Required</a> and indeed, we  have an additional layer in the stack trace and if I debug too long then I get a transaction timeout in my bean init.</p>
  
  <p>Looking at the following level in the stack-trace (slowly nexting out), I see that there is a transaction (well, two, actually):</p>
  
  <pre><code>SingletonSessionManager.constructAndInitBean() line: 377    
  
  wrap            weblogic.ejb.container.internal.InvocationWrapper  (id=15676)   
  L   callerTx    weblogic.transaction.internal.ServerTransactionImpl  (id=15681) 
  L   invokeTx    weblogic.transaction.internal.ServerTransactionImpl  (id=15683) 
  </code></pre>
  
  <p>I'll check if these were present in the pre-remove <code>@TransactionAttribute</code> scenario and also try and watch <code>ServerTransactionImpl</code>.</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>Last update for a while... However, I think I've traced the issue into <code>SingletonSessionManager#postCallback</code> which is called from <code>SingletonSessionManager#constructAndInitBean</code> in the original stack-trace above. (I'd need to confirm this though as my lead is determined by running through the transactional case). Will report back if/ when but it seems we may have a failure trying to rollback our non-existent transaction in here.</p>