4 Replies Latest reply on Sep 16, 2009 3:12 PM by anil kumar

    MDB - IllegalStateException: No event context active

    John Gilbert Apprentice

      I have an MDB that is a component and it calls SLSBs that are also components. When the SLSBs have a seam managed entityManager I am getting the following exception.

      2008-12-01 14:50:59,029 ERROR [org.jboss.seam.transaction.SynchronizationRegistry] Exception processing transaction Synchronization after completion
      java.lang.IllegalStateException: No event context active
           at org.jboss.seam.ScopeType.getContext(ScopeType.java:114)
           at org.jboss.seam.Component.getInstance(Component.java:1956)
           at org.jboss.seam.Component.getInstance(Component.java:1951)
           at org.jboss.seam.Component.getInstance(Component.java:1924)
           at org.jboss.seam.Component.getInstance(Component.java:1919)
           at org.jboss.seam.transaction.Transaction.instance(Transaction.java:36)
           at org.jboss.seam.persistence.ManagedPersistenceContext.close(ManagedPersistenceContext.java:191)
           at org.jboss.seam.persistence.ManagedPersistenceContext.afterCompletion(ManagedPersistenceContext.java:180)
           at org.jboss.seam.transaction.SynchronizationRegistry.afterTransactionCompletion(SynchronizationRegistry.java:42)
           at org.jboss.seam.transaction.EjbSynchronizations.afterCompletion(EjbSynchronizations.java:80)
           at org.jboss.ejb3.stateful.SessionSynchronizationInterceptor$SFSBSessionSynchronization.afterCompletion(SessionSynchronizationInterceptor.java:87)
           at org.jboss.tm.TransactionImpl.doAfterCompletion(TransactionImpl.java:3109)
           at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:1294)
           at org.jboss.tm.TxManager.commit(TxManager.java:588)
           at org.jboss.jms.asf.StdServerSession$TransactionDemarcation.end(StdServerSession.java:503)
           at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:219)
           at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:756)
           at java.lang.Thread.run(Thread.java:595)

      This looks like a bug, because the managed persistence context says that the contexts will already be destroyed by this point.

      public class ManagedPersistenceContext 
         public void afterCompletion(int status)
            synchronizationRegistered = false;
            //if ( !Contexts.isConversationContextActive() )
            if (destroyed)
               //in calls to MDBs and remote calls to SBs, the 
               //transaction doesn't commit until after contexts
               //are destroyed, so wait until the transaction
               //completes before closing the session
               //on the other hand, if we still have an active
               //conversation context, leave it open

      However, on close it immediately tries to get the Transaction from the event scope and fails.

      public class Transaction
         public static UserTransaction instance()
            return (UserTransaction) Component.getInstance(Transaction.class, ScopeType.EVENT);

      Am I doing something wrong or is this a bug?

        • 1. Re: MDB - IllegalStateException: No event context active
          John Gilbert Apprentice

          Still not sure if this is a bug or not, but wrapping the isActive call with an isEventContextActive() solved the issue.

          public class ManagedPersistenceContext 
             private void close()
                  if (Contexts.isEventContextActive()) 
                          boolean transactionActive = false;
                             transactionActive = Transaction.instance().isActive();
                          catch (SystemException se)
                             log.debug("could not get transaction status while destroying persistence context");
                          if ( transactionActive )
                             throw new IllegalStateException("attempting to destroy the persistence context while an active transaction exists (try installing <transaction:ejb-transaction/>)");
                if ( log.isDebugEnabled() )
                   log.debug("destroying seam managed persistence context for persistence unit: " + persistenceUnitJndiName);
                if (entityManager!=null && entityManager.isOpen())

          • 3. Re: MDB - IllegalStateException: No event context active
            Rafal Hajdacki Newbie

            Is somebody working on this? I believe I have the same situation when asynchronous method on SLSB is executed using EJB timer service.

            • 4. Re: MDB - IllegalStateException: No event context active
              anil kumar Newbie


              I am also getting similar error with SLSB.

              i added below code in calling component constructor

              if (!Contexts.isEventContextActive(

              ) && !


              now i am not getting, but i don't know is it right way.