6 Replies Latest reply on Apr 12, 2013 8:32 AM by irs

    Issue with StatefulKnowledgeSession

    irs Newbie

      Hi i have created a workflow using humantask with database. But when i am deploying the process i am getting this error "java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException".

      I debugged the java code and found the its not able to create "StatefulKnowledgeSession" when it reaches this part of the code it is not able to create a session. The value for the session id remains 0This is the code which i am implementing.

       


      @Test

           public void processInstancePersistentTest() throws Exception{

       

              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

              kbuilder.add(new ClassPathResource("HumanWorkflow.bpmn"), ResourceType.BPMN2);

       

              System.out.println("=== Knowledge Base Called ====");

       

              KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

              kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

       

              Environment env = EnvironmentFactory.newEnvironment();

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

              env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);       

              env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());

       

              System.out.println("=== Stateful Knowledge Session Called ====");

       

              final StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);

              int sessionId = ksession.getId();

       

              assertNotNull(sessionId);

              assertTrue(sessionId != 0);

       

              System.out.println("=== Human Task Handler Called ====");

              @SuppressWarnings("deprecation")

              CommandBasedWSHumanTaskHandler taskHandler = new CommandBasedWSHumanTaskHandler(ksession);

              ksession.getWorkItemManager().registerWorkItemHandler("Human Task",    taskHandler);

       

       

               ProcessInstance processInstance = ksession.createProcessInstance("com.sample.hello", null);

               System.out.println(">>> Let's Start the Process Instance");

               long processInstanceOne = processInstance.getId();

               ksession.startProcessInstance(processInstanceOne);

               ksession.dispose();

       

          }  

       

       

      and this is the error which i am getting on debugging the code.

       

       

          java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException

          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:142)

          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:66)

          at org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:122)

          at com.sample.HelloProcesTest.processInstancePersistentTest(HelloProcesTest.java:58)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

          at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

          at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

          at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

          at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

          at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

          at org.jbpm.test.KnowledgeSessionCleanup$1.evaluate(KnowledgeSessionCleanup.java:28)

          at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48)

          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)

          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

          at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

          at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)

          at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

      Caused by: java.lang.reflect.InvocationTargetException

          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

          at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

          at java.lang.reflect.Constructor.newInstance(Unknown Source)

          at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:128)

          ... 29 more

      Caused by: java.lang.NullPointerException

          at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:168)

          ... 34 more

       

      Regards

      Irshad

        • 1. Re: Issue with StatefulKnowledgeSession
          Maciej Swiderski Master

          have you declared jbpm runtime engine entities in the persistence.xml? I see that you use org.jbpm.task persistence unit and if that is default it does not have runtime engine entities declared and thus persistence does not work as expected for ksession.

           

          HTH

          • 2. Re: Issue with StatefulKnowledgeSession
            irs Newbie

            Hi Maciej

             

               Thanks for the reply. As per your guidence i went through the persistence.xml, this is my persistence.xml file

             

            <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

            <persistence version="1.0"

                xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

                                             http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd

                                             http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"

                xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                xmlns="http://java.sun.com/xml/ns/persistence">

             

                <persistence-unit name="org.jbpm.persistence.jpa">

                    <provider>org.hibernate.ejb.HibernatePersistence</provider>

                    <mapping-file>META-INF/JBPMorm.xml</mapping-file>

                    <mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>

             

                    <class>org.drools.persistence.info.SessionInfo</class>

                    <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>

                    <class>org.drools.persistence.info.WorkItemInfo</class>

                    <exclude-unlisted-classes>true</exclude-unlisted-classes>

             

                    <properties>

                        <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />

                        <property name="hibernate.connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver" />

                        <property name="hibernate.connection.url"

                            value="jdbc:jtds:sqlserver://localhost;DatabaseName=jbpmProcess" />

                        <property name="hibernate.connection.username" value="sa" />

                        <property name="hibernate.connection.password" value="root@123" />

                        <property name="hibernate.connection.autocommit" value="false" />

                        <property name="hibernate.max_fetch_depth" value="3" />

                        <property name="hibernate.hbm2ddl.auto" value="update" />

                        <property name="hibernate.show_sql" value="false" />

                    </properties>

             

                </persistence-unit>

             

                <persistence-unit name="org.jbpm.task">

                    <!-- Task Class -->

                    <provider>org.hibernate.ejb.HibernatePersistence</provider>

                    <mapping-file>META-INF/Taskorm.xml</mapping-file>

                    <class>org.jbpm.task.Attachment</class>

                    <class>org.jbpm.task.Content</class>

                    <class>org.jbpm.task.BooleanExpression</class>

                    <class>org.jbpm.task.Comment</class>

                    <class>org.jbpm.task.Deadline</class>

                    <class>org.jbpm.task.Comment</class>

                    <class>org.jbpm.task.Deadline</class>

                    <class>org.jbpm.task.Delegation</class>

                    <class>org.jbpm.task.Escalation</class>

                    <class>org.jbpm.task.Group</class>

                    <class>org.jbpm.task.I18NText</class>

                    <class>org.jbpm.task.Notification</class>

                    <class>org.jbpm.task.EmailNotification</class>

                    <class>org.jbpm.task.EmailNotificationHeader</class>

                    <class>org.jbpm.task.PeopleAssignments</class>

                    <class>org.jbpm.task.Reassignment</class>

                    <class>org.jbpm.task.Status</class>

                    <class>org.jbpm.task.Task</class>

                    <class>org.jbpm.task.TaskData</class>

                    <class>org.jbpm.task.SubTasksStrategy</class>

                    <class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>

                    <class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>

                    <class>org.jbpm.task.User</class>

             

                    <!-- Session Class -->

                    <class>org.drools.persistence.info.SessionInfo</class>

                    <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>

                    <class>org.drools.persistence.info.WorkItemInfo</class>

                    <exclude-unlisted-classes>true</exclude-unlisted-classes>

             

                    <properties>

                        <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />

                        <property name="hibernate.connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver" />

                        <property name="hibernate.connection.url"

                            value="jdbc:jtds:sqlserver://localhost;DatabaseName=task" />

                        <property name="hibernate.connection.username" value="sa" />

                        <property name="hibernate.connection.password" value="****" />

                        <property name="hibernate.connection.autocommit" value="false" />

                        <property name="hibernate.max_fetch_depth" value="3" />

                        <property name="hibernate.hbm2ddl.auto" value="update" />

                        <property name="hibernate.show_sql" value="false" />

                    </properties>

                </persistence-unit>

            </persistence>

             

             

            Regards

            Irshad

            .

            • 3. Re: Issue with StatefulKnowledgeSession
              irs Newbie

              I am still facing the IInvocationTargetException.I am using jbpm 5.4,  when  creating the StatefulKnowledgeSession without JPAKnowledgeService it is starting the process and executing, but with JPAKnowledgeService it is showing InvocationTargetException. I want to use JPAKnowledgeService to store the session in to the database and again reload it when required using JPAKnowledgeService.loadStatefulKnowledgeSession.

              I have attaced the related fles and  the log which i am getting while running the process in eclipse.

               

               

              regards,

              Irshad

              • 4. Re: Issue with StatefulKnowledgeSession
                joploya Newbie

                Hello,

                 

                I encountered a problem like yours.

                 

                After looking at other post I make these changes :

                 

                in persistent.xml :

                 

                <!-- jbpm Session --> 
                        <class>org.drools.persistence.info.SessionInfo</class>
                        <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
                        <class>org.drools.persistence.info.WorkItemInfo</class>
                

                 

                And the POM, I add the dependency for drools 5.5 :

                 

                <dependency>
                                         <groupId>org.drools</groupId>
                                         <artifactId>drools-compiler</artifactId>
                                         <version>5.5.0.Final</version>
                                    </dependency>
                

                 

                Regards,

                • 5. Re: Issue with StatefulKnowledgeSession
                  irs Newbie

                  Thanks for the reply sandra,

                  I am already having these class files in persistence.xml file and even the dependency which you mentioned is there. I debuged the code and on executing StatefulKnowledgeSession with JPASercive its throwing the error.I think it not able to get session for the kbase.

                   

                   

                  Regards ,

                  Irshad

                  • 6. Re: Issue with StatefulKnowledgeSession
                    irs Newbie

                    Found the solution.

                     

                    It was my mistake i was not adding the transaction type to the persistence

                     

                    so as i changed my persistence.xml file it worked fine for me.

                     

                    I made the following changes in my persistence.xml file

                     

                    <persistence-unit name="org.jbpm.task" transaction-type="JTA">

                     

                    and also add the transaction manager because trasaction manager is requiered if we are using JTA.

                     

                    <property name="hibernate.transaction.manager_lookup_class"

                                value="org.hibernate.transaction.BTMTransactionManagerLookup" />

                     

                    Regards

                    Irshad