3 Replies Latest reply on Aug 21, 2009 4:30 AM by kapitanpetko

    Exception calling component @Destroy method at end of @Asynchronous method call

    dozer

      Hi,


      I'm getting the following exception at the end of my @Asynchronous method call.
      I can't figure out why I'm getting it.  It does look like everything completed ok too.


      WARN  [Component] Exception calling component @Destroy method: em
      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:214)
           at org.jboss.seam.persistence.ManagedPersistenceContext.destroy(ManagedPersistenceContext.java:177)
           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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
           at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
           at org.jboss.seam.Component.callDestroyMethod(Component.java:2142)
           at org.jboss.seam.Component.destroy(Component.java:1436)
           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$ContextualAsynchronousRequest.cleanup(Asynchronous.java:91)
           at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:84)
           at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
           at org.jboss.seam.async.TimerServiceDispatcher.dispatch(TimerServiceDispatcher.java:50)
           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.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)
      11:01:48,484 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_4] TwoPhaseCoordinator.afterCompletion - returned failure for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@1a6b329
      



      Basically when i click on a button the backing bean action method  calls a Asynchronous method  on SLSB. This method then call a method on another SLSB which basically retrieves a list of entities and then loops through the entities and calls another SLSB to do all the processing.  This SLSB uses TransactionAttributeType.REQUIRES_NEW annotation on the method.


      When every thing finishes, I get the above exception.
      We are using Seam 2.1.1. and  Jboss 4.2.3
      In our components.xml file i have the following..(other parts aren't shown)




      <transaction:ejb-transaction /> 
      <persistence:managed-persistence-context name="em"
      auto-create="true"
      persistence-unit-jndi-name="java:/EntityManagerFactories/onePlaceDS" />
      <async:timer-service-dispatcher />





      Does anybody have any idea on how to fix this?

        • 1. Re: Exception calling component @Destroy method at end of @Asynchronous method call
          asookazian

          Sounds like one of the tx's is not committing or rolling back.  Possibly has something to do with the @Asynchronous invocation?  You need to determine which one and why.  That's not easy to do in my experience (I've been looking very intensely at 2PC/XA for a new Seam example and reading the Java Transaction Processing book by Mark Little - suffice it to say that transactions API in EJB3(CMT), JBoss and Seam are very complex).


          Two of the main components in the JBoss stack as far as tx's are concerned are org.jboss.resource.connectionmanager.TxConnectionManager and org.jboss.tm.TxManager.  So check out the pertinent methods in those classes and add debug brkpoints to trouble-shoot.


          Alternatively, I would de-layer your app temporarily by collapsing all three SLSBs into one SLSB to see how it behaves without the @Asynchronous invocation.

          • 2. Re: Exception calling component @Destroy method at end of @Asynchronous method call
            dozer

            I've turned debugging on and it looks like my asynchronous method finishes correctly and then seam trys to destroy the seam components used.  And it's trying to destroy the entityManager, where the exception occurs as the transaction is still active.  I'm guessing its because the entityManager is been destroyed before the org.jboss.seam.transaction.synchronizations component?


            Does this make sense?  is it a bug?




            2009-08-21 12:36:43,562 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
            2009-08-21 12:36:43,562 DEBUG [org.jboss.ejb3.entity.ManagedEntityManagerFactory] ************** closing entity managersession **************
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying: reportParameters
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying: trialBalance
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.international.localeSelector
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying business process context
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying conversation context
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.international.statusMessages
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.persistence.persistenceContexts
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying: em
            2009-08-21 12:36:43,562 WARN  [org.jboss.seam.Component] Exception calling component @Destroy method: em
            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:214)
                 at org.jboss.seam.persistence.ManagedPersistenceContext.destroy(ManagedPersistenceContext.java:177)
                 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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                 at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
                 at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
                 at org.jboss.seam.Component.callDestroyMethod(Component.java:2142)
                 at org.jboss.seam.Component.destroy(Component.java:1436)
                 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$ContextualAsynchronousRequest.cleanup(Asynchronous.java:91)
                 at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:84)
                 at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
                 at org.jboss.seam.async.TimerServiceDispatcher.dispatch(TimerServiceDispatcher.java:50)
                 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.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)
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] flushing server-side conversation context
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] flushing session context
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying event context
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.core.manager
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying: timer
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.transaction.synchronizations
            2009-08-21 12:36:43,562 DEBUG [org.jboss.seam.transaction.EjbSynchronizations] afterBegin
            2009-08-21 12:36:43,562 DEBUG [org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor] ++++ LongLivedSessionPropagationInterceptor
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.core.events
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Contexts] destroying: trialBalanceAction
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] trying to inject with hierarchical context search: em
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Contexts] found in conversation context: em
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] trying to inject with hierarchical context search: currentUser
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] trying to inject with hierarchical context search: facesMessages
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.core.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.cache.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.transaction.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.framework.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.web.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.faces.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.international.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.theme.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.pageflow.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.bpm.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.jms.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.mail.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.security.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.security.management.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.security.permission.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.security.openid.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.captcha.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.excel.exporter.org
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.international
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Contexts] found in conversation context: org.jboss.seam.international.statusMessages
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] trying to inject with hierarchical context search: messages
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.international.messages
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.Component] trying to inject with hierarchical context search: reportParameters
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Contexts] found in session context: reportParameters
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.international.messages
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.transaction.transaction
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.web.servletContexts
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.contexts.Lifecycle] <<< End call
            2009-08-21 12:36:43,578 DEBUG [org.jboss.seam.transaction.EjbSynchronizations] beforeCompletion
            2009-08-21 12:36:43,578 WARN  [com.arjuna.ats.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_4] TwoPhaseCoordinator.afterCompletion - returned failure for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@1deb889
            2009-08-21 12:36:43,578 DEBUG [org.jboss.ejb.txtimer.TimerImpl] Timer was not registered with Tx, resetting state: [id=1250814745110,target=[target=jboss.j2ee:service=EJB3,ear=1place.ear,jar=jboss-seam.jar,name=TimerServiceDispatcher],remaining=-98156,periode=0,in_timeout]
            2009-08-21 12:36:43,578 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: expired
            2009-08-21 12:36:43,578 DEBUG [org.jboss.ejb.txtimer.TimerImpl] killTimer: [id=1250814745110,target=[target=jboss.j2ee:service=EJB3,ear=1place.ear,jar=jboss-seam.jar,name=TimerServiceDispatcher],remaining=-98156,periode=0,expired]
            
            



            • 3. Re: Exception calling component @Destroy method at end of @Asynchronous method call
              kapitanpetko

              Could you show the relevant code for your SLSBs? Looks like you are using the SMPC (@In EntityManager em) in your asynchronous components,
              and that is the source of your troubles. SMPC doesn't mix well with REQUIRES_NEW, so you could have a problem there. In general,
              SPMC does not give you any advantages for asynchronous methods (there is no conversation), so use @PersistenceContext (container managed)
              for async components.