5 Replies Latest reply on Aug 14, 2008 1:17 PM by Sean Burns

    EjbSynchronisations afterCompletion() not called

    stefan meyer Newbie

      I am using Seam with MDBs on Jboss 4.2.2GA and Seam 2.0.1GA. Since the EjbSynchronisations (SFSB) is destroyed with the Contexts, the StatefulRemoveInterceptor remves it from the cache in afterCompletion() of the UserTransaction. This is before the EjbSynchronisations own afterCompletion() is called and so the latter fails.


      My ugly workaround is to explicitly create and destroy EjbSynchronisations upon entering the MDB. Thus only one Call to EjbSynchronisations fails. All others (stemming from to all the other calls to registerSynchronisation (or any other method) on EjbSynchronisations) succeed because of the order of synchronisations being performed.


      Is it me, Seam or Jboss?

        • 1. Re: EjbSynchronisations afterCompletion() not called
          stefan meyer Newbie

          Another Problem is the ManagedPersistenceContext calling Transaction.instance() in close. This is called from afterCompletion in case of MDBs. The comment states that the contexts will be destroyed at this point.

          • 2. Re: EjbSynchronisations afterCompletion() not called
            Pete Muir Master

            File a JIRA issue with an example to show the problem and step by step reproduction instructions.

            • 3. Re: EjbSynchronisations afterCompletion() not called
              Sean Burns Newbie

              Hi,


              I had a look at the jira https://jira.jboss.org/jira/browse/JBSEAM-2973, and not much has happened on it (including a estimated fixed version).


              I can easily reproduce this with


              @Name("loopTest")
              @Stateless
              @TransactionManagement(TransactionManagementType.BEAN)
              public class LoopTest implements LoopTestLocal {
                   
                   @In
                   private EntityManager entityManager;
                   
                   @Observer("LOOP")
                   public void loop(long id) {
                        RequestMoney result = entityManager.find(RequestMoney.class, id);
                        System.out.println("Looping"+ result.getId());
                        Events.instance().raiseTimedEvent("LOOP",new TimerSchedule(5000L), id);
                   }
              }



              with looping exception


              17:23:01,299 INFO  [STDOUT] Looping12
              17:23:01,303 WARN  [Component] Exception calling component @Destroy method: entityManager
              java.lang.IllegalStateException: attempting to destroy the persistence context while an active transaction exists (try installing <transaction:ejb-transaction/>)
                   at org.jboss.seam.persistence.ManagedPersistenceContext.close(ManagedPersistenceContext.java:216)
                   at org.jboss.seam.persistence.ManagedPersistenceContext.destroy(ManagedPersistenceContext.java:179)
                   at sun.reflect.GeneratedMethodAccessor182.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:585)
                   at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
                   at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
                   at org.jboss.seam.Component.callComponentMethod(Component.java:2092)
                   at org.jboss.seam.Component.callDestroyMethod(Component.java:2023)
                   at org.jboss.seam.Component.destroy(Component.java:1334)
                   at org.jboss.seam.contexts.Contexts.destroy(Contexts.java:251)
                   at org.jboss.seam.contexts.Contexts.flushAndDestroyContexts(Contexts.java:363)
                   at org.jboss.seam.contexts.Lifecycle.endCall(Lifecycle.java:96)
                   at org.jboss.seam.async.Asynchronous.execute(Asynchronous.java:50)
                   at org.jboss.seam.async.TimerServiceDispatcher.dispatch(TimerServiceDispatcher.java:50)
                   at sun.reflect.GeneratedMethodAccessor187.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:585)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                   at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
                   at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:108)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.stateless.StatelessContainer.callTimeout(StatelessContainer.java:175)
                   at org.jboss.ejb.txtimer.TimerImpl$TimerTaskImpl.run(TimerImpl.java:561)
                   at java.util.TimerThread.mainLoop(Timer.java:512)
                   at java.util.TimerThread.run(Timer.java:462)



              Is there a work around?


              Thanks,
              Sean Burns.



              • 4. Re: EjbSynchronisations afterCompletion() not called
                Pete Muir Master

                Please attach this example to the issue, then I can take a look.


                Thanks

                • 5. Re: EjbSynchronisations afterCompletion() not called
                  Sean Burns Newbie

                  Switching to XA transactions fixed everything for me