10 Replies Latest reply on Dec 19, 2013 3:49 AM by Laura delli Paoli

    InvocationTargetException on creating StatefulKnowledgeSession

    Laura delli Paoli Master

      Hello everybody,

      I'm facing a strange problem and I'm wondering if someone has encountered the same issue.

      I'm trying to start a jbpm workflow from a jms consumer (i.e. after receiving a jms message), but on creating a StatefulKnowledgeSession

       

      if (persistenceEnabled) {

        Environment env = KnowledgeBaseFactory.newEnvironment();

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");

        KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);

        env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

        BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager();

        env.set(EnvironmentName.TRANSACTION_MANAGER, transactionManager);

        env.set(EnvironmentName.TRANSACTION, transactionManager.getTransaction());

        if (sessionId == -1) {

             ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);

        } else {

             ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, config, env);

             ksession.dispose();

             ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);

        }

        boolean humanTaskEnabled = properties.getProperty("taskservice.enabled", "false").equalsIgnoreCase("true");

        if (humanTaskEnabled) {

             String transport = properties.getProperty("taskservice.transport", "hornetq");

        if ("mina".equals(transport)) {

             ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new MinaHTWorkItemHandler(ksession));

        } else if ("hornetq".equals(transport)) {

             ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new AsyncHornetQHTWorkItemHandler(ksession, true));

        } else {

             throw new RuntimeException("Unknown task service transport " + transport);

        }

        }

      }

       

      I get a java.lang.reflect.InvocationTargetException. If I use the same code, but drive the workflow using a webService, all works fine.

      See persistence.xml attacched.

      Can anyone help me?

       

      Laura

        • 1. Re: InvocationTargetException on creating StatefulKnowledgeSession
          Laura delli Paoli Master

          No suggestions???

           

          Here a trace:

           

          23:26:50,993 WARN  [org.hibernate.ejb.internal.EntityManagerFactoryRegistry] (Thread-6 (HornetQ-client-global-threads-1109289756)) HHH000436: Entity manager factory name (org.jbpm.persistence.jpa) is already registered.  If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'

          23:26:51,003 ERROR [eu.discoveryreply.applicationLayer.jmsconsumer.MCFMessageConsumer] (Thread-6 (HornetQ-client-global-threads-1109289756)) Error while launching workflow: java.lang.reflect.InvocationTargetException: java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException

            at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:142) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

            at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:66) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

            at org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:122) [knowledge-api-5.5.0.Final.jar:5.5.0.Final]

            at eu.discoveryreply.serviceLayer.jbpm.JBpmHelper.loadStatefulKnowledgeSession(JBpmHelper.java:78) [classes:]

            at eu.discoveryreply.serviceLayer.jbpm.JBpmHelper.newStatefulKnowledgeSession(JBpmHelper.java:48) [classes:]

            at eu.discoveryreply.serviceLayer.jbpm.JBpmJmsConsumerDrivenWkfLauncher.startWorkflow(JBpmJmsConsumerDrivenWkfLauncher.java:58) [classes:]

            at eu.discoveryreply.applicationLayer.jmsconsumer.MCFMessageConsumer.onMessage(MCFMessageConsumer.java:92) [classes:]

            at org.hornetq.jms.client.JMSMessageListenerWrapper.onMessage(JMSMessageListenerWrapper.java:91)

            at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:983) [hornetq-core-2.2.10.Final.jar:]

            at org.hornetq.core.client.impl.ClientConsumerImpl.access$400(ClientConsumerImpl.java:48) [hornetq-core-2.2.10.Final.jar:]

            at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1113) [hornetq-core-2.2.10.Final.jar:]

            at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100) [hornetq-core-2.2.10.Final.jar:]

            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_23]

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_23]

            at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_23]

          Caused by: java.lang.reflect.InvocationTargetException

            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_23]

            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_23]

            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_23]

            at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_23]

            at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:128) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

            ... 14 more

          Caused by: java.lang.IllegalStateException: Unable to find transaction: java:comp/UserTransaction

            at org.drools.persistence.jta.JtaTransactionManager.findUserTransaction(JtaTransactionManager.java:124) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

            at org.drools.persistence.jta.JtaTransactionManager.<init>(JtaTransactionManager.java:69) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

            at org.drools.persistence.SingleSessionCommandService.initTransactionManager(SingleSessionCommandService.java:303) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

            at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:117) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

            ... 19 more

          Caused by: javax.naming.NameNotFoundException: java:comp/UserTransaction

            at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:121)

            at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)

            at javax.naming.InitialContext.lookup(InitialContext.java:392) [rt.jar:1.6.0_23]

            at org.drools.persistence.jta.JtaTransactionManager.findUserTransaction(JtaTransactionManager.java:119) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

            ... 22 more

          • 2. Re: InvocationTargetException on creating StatefulKnowledgeSession
            synclpz Novice

            Are you sure you have properly configured transaction manager?

             

            this line:

                 BitronixTransactionManager transactionManager = TransactionManagerServices.getTransactionManager();

            produces your error:

                 javax.naming.NameNotFoundException: java:comp/UserTransaction


            • 3. Re: InvocationTargetException on creating StatefulKnowledgeSession
              Laura delli Paoli Master

              Hi Viktor,

              Thanks for your answare. No, I get the error on this line:

               

                ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);


              How can I chack that the transaction manager is properly configured?

              • 4. Re: InvocationTargetException on creating StatefulKnowledgeSession
                synclpz Novice

                Sorry, i misunderstood the trace... Transaction manager lookup is ok, because you invoke transactionManager.getTransaction() and do not get NPE :-)

                 

                Could you check that "transactionManager.getTransaction()" does not return null? Seems like it tries to lookup java:comp/UserTransaction upon newStatefulKnowledgeSession being called. May be if   env.set(EnvironmentName.TRANSACTION, transactionManager.getTransaction()); sets not null it would not try to lookup? I don't really know, but you may try...

                • 5. Re: InvocationTargetException on creating StatefulKnowledgeSession
                  Laura delli Paoli Master

                  Yes, it returns null

                   

                  if I avoid passing transaction to my environment I get the same error.

                   

                  Laura

                  • 6. Re: InvocationTargetException on creating StatefulKnowledgeSession
                    jaikiran pai Master

                    Moved to jBPM forum. They might know more of this.

                    • 7. Re: InvocationTargetException on creating StatefulKnowledgeSession
                      synclpz Novice

                      Seems like issues with Bitronix. It should not return null on getTransaction() or you are not using it the right way :-)

                      • 8. Re: Re: InvocationTargetException on creating StatefulKnowledgeSession
                        Laura delli Paoli Master

                        I succeded in obtaining a not null transaction by beginning transaction (see screen attached). Now I get the following error:

                         

                        12:22:52,337 WARN  [bitronix.tm.Configuration] (Thread-1 (HornetQ-client-global-threads-72961245)) cannot get this JVM unique ID. Make sure it is configured and you only use ASCII characters. Will use IP address instead (unsafe for production usage!).

                        12:22:52,341 INFO  [bitronix.tm.Configuration] (Thread-1 (HornetQ-client-global-threads-72961245)) JVM unique ID: <127.0.0.1>

                        12:22:52,521 WARN  [bitronix.tm.journal.DiskJournal] (Thread-1 (HornetQ-client-global-threads-72961245)) active log file is unclean, did you call BitronixTransactionManager.shutdown() at the end of the last run?

                        12:22:52,557 WARN  [bitronix.tm.utils.ManagementRegistrar] (Thread-1 (HornetQ-client-global-threads-72961245)) cannot register object with name bitronix.tm:type=Recoverer,ServerId=127_0_0_1: bitronix.tm.internal.BitronixRuntimeException: cannot call method 'registerMBean'

                          at bitronix.tm.utils.ManagementRegistrar.mbeanServerCall(ManagementRegistrar.java:123) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.utils.ManagementRegistrar.register(ManagementRegistrar.java:86) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.recovery.Recoverer.<init>(Recoverer.java:104) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.TransactionManagerServices.getRecoverer(TransactionManagerServices.java:139) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.BitronixTransactionManager.<init>(BitronixTransactionManager.java:64) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.TransactionManagerServices.getTransactionManager(TransactionManagerServices.java:62) [btm-2.1.2.jar:2.1.2]

                          at eu.discoveryreply.serviceLayer.jbpm.JBpmHelper.loadStatefulKnowledgeSession(JBpmHelper.java:77) [classes:]

                          at eu.discoveryreply.serviceLayer.jbpm.JBpmHelper.newStatefulKnowledgeSession(JBpmHelper.java:54) [classes:]

                          at eu.discoveryreply.serviceLayer.jbpm.JBpmJmsConsumerDrivenWkfLauncher.startWorkflow(JBpmJmsConsumerDrivenWkfLauncher.java:58) [classes:]

                          at eu.discoveryreply.applicationLayer.jmsconsumer.MCFMessageConsumer.onMessage(MCFMessageConsumer.java:92) [classes:]

                          at org.hornetq.jms.client.JMSMessageListenerWrapper.onMessage(JMSMessageListenerWrapper.java:91) [jboss-client.jar:7.1.1.Final]

                          at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:983) [hornetq-core-2.2.10.Final.jar:]

                          at org.hornetq.core.client.impl.ClientConsumerImpl.access$400(ClientConsumerImpl.java:48) [hornetq-core-2.2.10.Final.jar:]

                          at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1113) [hornetq-core-2.2.10.Final.jar:]

                          at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100) [hornetq-core-2.2.10.Final.jar:]

                          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_23]

                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_23]

                          at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_23]

                        Caused by: java.lang.IllegalAccessException: Class bitronix.tm.utils.ManagementRegistrar can not access a member of class org.jboss.as.jmx.PluggableMBeanServerImpl with modifiers "public"

                          at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65) [rt.jar:1.6.0_23]

                          at java.lang.reflect.Method.invoke(Method.java:588) [rt.jar:1.6.0_23]

                          at bitronix.tm.utils.ManagementRegistrar.mbeanServerCall(ManagementRegistrar.java:121) [btm-2.1.2.jar:2.1.2]

                          ... 17 more

                         

                         

                        12:22:52,596 INFO  [bitronix.tm.recovery.Recoverer] (Thread-1 (HornetQ-client-global-threads-72961245)) recovery committed 0 dangling transaction(s) and rolled back 0 aborted transaction(s) on 0 resource(s) [] (restricted to serverId '127.0.0.1')

                        12:22:52,634 WARN  [bitronix.tm.utils.ManagementRegistrar] (Thread-1 (HornetQ-client-global-threads-72961245)) cannot register object with name bitronix.tm:type=Transaction,Gtrid=3132372E302E302E3100000142F0D83D4F00000000: bitronix.tm.internal.BitronixRuntimeException: cannot call method 'registerMBean'

                          at bitronix.tm.utils.ManagementRegistrar.mbeanServerCall(ManagementRegistrar.java:123) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.utils.ManagementRegistrar.register(ManagementRegistrar.java:86) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.BitronixTransaction.setStatus(BitronixTransaction.java:340) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.BitronixTransaction.setStatus(BitronixTransaction.java:323) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.BitronixTransaction.setActive(BitronixTransaction.java:314) [btm-2.1.2.jar:2.1.2]

                          at bitronix.tm.BitronixTransactionManager.begin(BitronixTransactionManager.java:103) [btm-2.1.2.jar:2.1.2]

                          at eu.discoveryreply.serviceLayer.jbpm.JBpmHelper.loadStatefulKnowledgeSession(JBpmHelper.java:79) [classes:]

                          at eu.discoveryreply.serviceLayer.jbpm.JBpmHelper.newStatefulKnowledgeSession(JBpmHelper.java:54) [classes:]

                          at eu.discoveryreply.serviceLayer.jbpm.JBpmJmsConsumerDrivenWkfLauncher.startWorkflow(JBpmJmsConsumerDrivenWkfLauncher.java:58) [classes:]

                          at eu.discoveryreply.applicationLayer.jmsconsumer.MCFMessageConsumer.onMessage(MCFMessageConsumer.java:92) [classes:]

                          at org.hornetq.jms.client.JMSMessageListenerWrapper.onMessage(JMSMessageListenerWrapper.java:91) [jboss-client.jar:7.1.1.Final]

                          at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:983) [hornetq-core-2.2.10.Final.jar:]

                          at org.hornetq.core.client.impl.ClientConsumerImpl.access$400(ClientConsumerImpl.java:48) [hornetq-core-2.2.10.Final.jar:]

                          at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1113) [hornetq-core-2.2.10.Final.jar:]

                          at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100) [hornetq-core-2.2.10.Final.jar:]

                          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_23]

                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_23]

                          at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_23]

                        Caused by: java.lang.IllegalAccessException: Class bitronix.tm.utils.ManagementRegistrar can not access a member of class org.jboss.as.jmx.PluggableMBeanServerImpl with modifiers "public"

                          at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65) [rt.jar:1.6.0_23]

                          at java.lang.reflect.Method.invoke(Method.java:588) [rt.jar:1.6.0_23]

                          at bitronix.tm.utils.ManagementRegistrar.mbeanServerCall(ManagementRegistrar.java:121) [btm-2.1.2.jar:2.1.2]

                          ... 17 more

                         

                         

                        12:23:53,159 WARN  [bitronix.tm.BitronixTransaction] (bitronix-scheduler) transaction timed out: a Bitronix Transaction with GTRID [3132372E302E302E3100000142F0D83D4F00000000], status=MARKED_ROLLBACK, 0 resource(s) enlisted (started Sat Dec 14 12:22:52 CET 2013)

                        12:25:06,178 ERROR [eu.discoveryreply.applicationLayer.jmsconsumer.MCFMessageConsumer] (Thread-1 (HornetQ-client-global-threads-72961245)) Error while launching workflow: java.lang.reflect.InvocationTargetException: java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException

                          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:142) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

                          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:66) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

                          at org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:122) [knowledge-api-5.5.0.Final.jar:5.5.0.Final]

                          at eu.discoveryreply.serviceLayer.jbpm.JBpmHelper.loadStatefulKnowledgeSession(JBpmHelper.java:87) [classes:]

                          at eu.discoveryreply.serviceLayer.jbpm.JBpmHelper.newStatefulKnowledgeSession(JBpmHelper.java:54) [classes:]

                          at eu.discoveryreply.serviceLayer.jbpm.JBpmJmsConsumerDrivenWkfLauncher.startWorkflow(JBpmJmsConsumerDrivenWkfLauncher.java:58) [classes:]

                          at eu.discoveryreply.applicationLayer.jmsconsumer.MCFMessageConsumer.onMessage(MCFMessageConsumer.java:92) [classes:]

                          at org.hornetq.jms.client.JMSMessageListenerWrapper.onMessage(JMSMessageListenerWrapper.java:91) [jboss-client.jar:7.1.1.Final]

                          at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:983) [hornetq-core-2.2.10.Final.jar:]

                          at org.hornetq.core.client.impl.ClientConsumerImpl.access$400(ClientConsumerImpl.java:48) [hornetq-core-2.2.10.Final.jar:]

                          at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1113) [hornetq-core-2.2.10.Final.jar:]

                          at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100) [hornetq-core-2.2.10.Final.jar:]

                          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_23]

                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_23]

                          at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_23]

                        Caused by: java.lang.reflect.InvocationTargetException

                          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_23]

                          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_23]

                          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_23]

                          at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_23]

                          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:128) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

                          ... 14 more

                        Caused by: java.lang.ClassCastException: bitronix.tm.BitronixTransaction cannot be cast to javax.transaction.UserTransaction

                          at org.drools.persistence.jta.JtaTransactionManager.<init>(JtaTransactionManager.java:69) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

                          at org.drools.persistence.SingleSessionCommandService.initTransactionManager(SingleSessionCommandService.java:303) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

                          at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:117) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]

                          ... 19 more

                        • 9. Re: InvocationTargetException on creating StatefulKnowledgeSession
                          Laura delli Paoli Master

                          No suggestion? Please help me!!!

                           

                          I cannot understand why adding a queue reader to a webapp may change jbpm behaviour.

                           

                          Laura