3 Replies Latest reply on Apr 12, 2007 7:30 AM by pmuir

    No application context active when raising event

      Hi,

      I get

      java.lang.IllegalStateException: No application context active
      when updating an @Entity from a MDB. The @Entity raise an event on the @PostUpdate. If commenting the call to raiseEvent everything works. It also works when updating the @Entity from the user interface and the event is raised.

      -A message is placed on a JMS queue which is picked up by a MDB (The MDB is a seam component).
      -The MDB make a call to a workhandler (also seam component) , which again ends up in updating an ARRIVAL through the Arrival Entity.
      -When Arrival is updated the following code is executed through @PostUpdate:
      @PostUpdate
       public void afterUpdate(Arrival entity)
       {
       Events.instance().raiseEvent("arrivalUpdate", entity);
       }

      -And this causes the following stacktrace:
      11:30:34,436 INFO [STDOUT] Hibernate:
       update
       ARRIVAL
       set
       ARR_ETA=?,
       ARR_PTA=?,
       ARR_ATA=?,
       COS_ID=?
       where
       ARR_ID=?
      11:30:34,451 ERROR [JmsServerSession] org.jboss.resource.adapter.jms.inflow.JmsServerSession@1b602b9 failed to commit/rollback
      org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=jarle/49, BranchQual=, localId=49] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.PersistenceException: java.lang.IllegalStateException: No application context active)
       at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:372)
       at org.jboss.tm.TxManager.commit(TxManager.java:240)
       at org.jboss.resource.adapter.jms.inflow.JmsServerSession$XATransactionDemarcationStrategy.end(JmsServerSession.java:471)
       at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:260)
       at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
       at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
       at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.persistence.PersistenceException: java.lang.IllegalStateException: No application context active
       at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:527)
       at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
       at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
       at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
       ... 7 more
      Caused by: java.lang.IllegalStateException: No application context active
       at org.jboss.seam.Component.forName(Component.java:1577)
       at org.jboss.seam.Component.getInstance(Component.java:1627)
       at org.jboss.seam.Component.getInstance(Component.java:1622)
       at org.jboss.seam.Component.getInstance(Component.java:1599)
       at org.jboss.seam.Component.getInstance(Component.java:1594)
       at org.jboss.seam.core.Events.instance(Events.java:138)
       at com.logit.sailingplan.domain.ArrivalListener.afterUpdate(ArrivalListener.java:84)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.hibernate.ejb.event.ListenerCallback.invoke(ListenerCallback.java:31)
       at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:78)
       at org.hibernate.ejb.event.EntityCallbackHandler.postUpdate(EntityCallbackHandler.java:67)
       at org.hibernate.ejb.event.EJB3PostUpdateEventListener.onPostUpdate(EJB3PostUpdateEventListener.java:40)
       at org.hibernate.action.EntityUpdateAction.postUpdate(EntityUpdateAction.java:183)
       at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:162)
       at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
       at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
       ... 10 more


      -By commenting the raiseEvent it works and the Arrival is updated, but I'd like to have my event raised.

      -My @Observer for the Event is empty (just log)

      Anyone know what causes this behaviour? (I'm using seam 1.2.1.GA)

      Regards Jarle

        • 1. Re: No application context active when raising event
          pmuir

          http://docs.jboss.com/seam/1.2.1.GA/reference/en/html/concepts.html#d0e2752

          Slightly obscure, I know, but Seam doesn't support context demarcation inside of entity beans so your events won't work. You could, if you needed, set up the context manually.

          • 2. Re: No application context active when raising event

            Thanks for your reply

            If I understand this correctly. The reason for my event beeing called when updating using the web interface is that my seam components, including the entity, is invoked via the context variable, whereas when updating from a message-driven-bean which listen to a queue, and not bound to a seam context, it fails?

            My idea was to have an event triggered whenver the Arrival was updated, to perform some other operations not relevant to the update it self (e.g. check differens between two arrival times).

            I kind'a like the event, but not sure on how and where I should set up the context manually, as suggested by petemuir. Help appriciated :)

            Regards Jarle

            • 3. Re: No application context active when raising event
              pmuir

               

              "novare" wrote:
              The reason for my event beeing called when updating using the web interface is that my seam components, including the entity, is invoked via the context variable, whereas when updating from a message-driven-bean which listen to a queue, and not bound to a seam context, it fails?


              No, it's because you are raising an event inside an entity