4 Replies Latest reply on Jun 29, 2012 4:02 PM by Bira Neto

    Null cmdScopedEntityManager during stateful session load

    Bira Neto Newbie

      I am getting a nullpointerexception during ksession load due to a null cmdScopedEntityManager (from JpaPersistenceContextManager).

       

      First I created a conditional event and executed a instance of this workflow (which results in an active workflow waiting for a condition)

      After restarting my server, the session load will fire (or try to fire) an ActivationCreatedEventImpl for my pending rule (named after my process.... RuleFlowStateNode-conditionalTest_2_0-7)

       

      The problem though.... is that when calling getProcessInstancesWaitingForEvent it will try to call a getProcessPersistenceContext() implementation which tries to return a new JpaProcessPersistenceContext( cmdScopedEntityManager );

      This cmdScopedEntityManager was not initialized yet though. It seems to be lazy initialized during beginCommandScopedEntityManager (from JpaPersistenceContextManager).

       

      Is that a bug or is there some way or something else I need to add to my environment to use this properly?

        • 1. Re: Null cmdScopedEntityManager during stateful session load
          Maciej Swiderski Master

          could you upload your process definition and some details about your environment setup so we could verify if that is an issue or any configuration is missing?

          • 2. Re: Null cmdScopedEntityManager during stateful session load
            Bira Neto Newbie

            I'm using jbpm 5.3 on tomcat with spring and Bitronix. Postgres DB.

             

            My environment is being created like this:

             

              EntityManagerFactory emf = Persistence.createEntityManagerFactory("com.framework.jpa");

                                Environment env = KnowledgeBaseFactory.newEnvironment();

             

                                env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

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

                                env.set(EnvironmentName.TRANSACTION, ut);

             

                                return env;

             

            The process definition is not big... there is a lot of calls from my framework which I must say call no Jbpm methods. The important part is the two conditionalEvents that lead to one line of execution reach the end event and the other being blocked. When restarting the server the deserialization fails.

             

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

            <definitions id="Definition"

            targetNamespace="http://jbpm.org/example/bpmn2"

            typeLanguage="http://www.java.com/javaTypes"

            xmlns:java="http://drools.org/semantics/java"

            expressionLanguage="http://www.mvel.org/2.0"

            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

            xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"

            xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"

            xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"

            xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"

            xmlns:di="http://www.omg.org/spec/DD/20100524/DI"

            xmlns:tns="http://www.jboss.org/drools">

            <itemDefinition id="CTX_PROCESS_IDItem" structureRef="java.lang.Long" />

             

            <process processType="Private" isExecutable="true"

            id="conditionalTest_2_0"  tns:packageName="defaultPackage" name="conditionalTest_2.0" >

            <extensionElements>

            <tns:import name="com.entities.*" />

            <tns:import name="com.core.services.ServicePkAspect" />

            </extensionElements>

            <property id="CTX_PROCESS_ID" itemSubjectRef="tns:CTX_PROCESS_IDItem"/>

            <endEvent id="id_3" name="id_3" ><incoming>id_17</incoming>

            </endEvent>

            <scriptTask id="id_7" name="id_7" ><incoming>id_10</incoming>

            <outgoing>id_16</outgoing>

             

            <script>ServicePkAspect.processAroundExecute("workflowServicePk", "executeRule", null, new String[]{"testRuleParam","testRuleParam","132710"}, CTX_PROCESS_ID);</script>

            </scriptTask>

            <exclusiveGateway id="id_6" name="id_6"  gatewayDirection="Converging"><incoming>id_12</incoming>

            <incoming>id_11</incoming>

            <outgoing>id_17</outgoing>

            </exclusiveGateway>

            <scriptTask id="id_2" name="id_2" ><incoming>id_13</incoming>

            <outgoing>id_10</outgoing>

             

            <script> ServicePkAspect.processAroundExecute("workflowServicePk", "executePrepareTestRule", null, null, CTX_PROCESS_ID); return true; </script>

            </scriptTask>

            <startEvent id="id_4" name="id_4"><outgoing>id_13</outgoing>

            </startEvent>

            <parallelGateway id="id_8" name="id_8" gatewayDirection="Diverging"><incoming>id_16</incoming>

            <outgoing>id_14</outgoing>

            <outgoing>id_15</outgoing>

            </parallelGateway>

            <intermediateCatchEvent id="id_5" name="id_5">

             

             

            <incoming>id_15</incoming>

            <outgoing>id_12</outgoing>

            <conditionalEventDefinition>

            <condition xsi:type="tFormalExpression" > UserPk(idUser &gt; 150)

            </condition>

            </conditionalEventDefinition>

             

            </intermediateCatchEvent>

            <intermediateCatchEvent id="id_9" name="id_9">

             

             

            <incoming>id_14</incoming>

            <outgoing>id_11</outgoing>

            <conditionalEventDefinition>

            <condition xsi:type="tFormalExpression" > UserPk(idUser &lt;= 150)

            </condition>

            </conditionalEventDefinition>

             

            </intermediateCatchEvent>

            <sequenceFlow id="id_14" name="id_14" sourceRef="id_8" targetRef="id_9" > </sequenceFlow>

            <sequenceFlow id="id_11" name="id_11" sourceRef="id_9" targetRef="id_6" > </sequenceFlow>

            <sequenceFlow id="id_13" name="id_13" sourceRef="id_4" targetRef="id_2" > </sequenceFlow>

            <sequenceFlow id="id_16" name="id_16" sourceRef="id_7" targetRef="id_8" > </sequenceFlow>

            <sequenceFlow id="id_17" name="id_17" sourceRef="id_6" targetRef="id_3" >

            <conditionExpression xsi:type="tFormalExpression">

            return true;

            </conditionExpression> </sequenceFlow>

            <sequenceFlow id="id_12" name="id_12" sourceRef="id_5" targetRef="id_6" > </sequenceFlow>

            <sequenceFlow id="id_15" name="id_15" sourceRef="id_8" targetRef="id_5" > </sequenceFlow>

            <sequenceFlow id="id_10" name="id_10" sourceRef="id_2" targetRef="id_7" > </sequenceFlow>

             

             

            </process>

            </definitions>

             

            When restarting the server with

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

            I get the exception below caused by a null pointer exception as already mentioned on the first post. Maybe it is worth to mention that the var appScopedEntityManager is initialized.

             

            java.lang.RuntimeException: Unable to load session snapshot

                      at org.drools.persistence.SessionMarshallingHelper.loadSnapshot(SessionMarshallingHelper.java:96)

                      at org.drools.persistence.SingleSessionCommandService.initKsession(SingleSessionCommandService.java:253)

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

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

                      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

                      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

                      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

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

                      at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.loadStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:84)

                      at org.drools.persistence.jpa.JPAKnowledgeService.loadStatefulKnowledgeSession(JPAKnowledgeService.java:131)

                      at com.perkons.frameworkpk.fpk.core.workflows.WorkflowManagerPk.loadStatefulSession(WorkflowManagerPk.java:403)

                      at com.perkons.frameworkpk.fpk.core.workflows.WorkflowManagerPk.initialize(WorkflowManagerPk.java:120)

                      at com.perkons.frameworkpk.fpk.core.ContextLoaderListenerPk.contextInitialized(ContextLoaderListenerPk.java:92)

                      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)

                      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)

                      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)

                      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)

                      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)

                      at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)

                      at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)

                      at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)

                      at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)

                      at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)

                      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)

                      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)

                      at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

                      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)

                      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

                      at org.apache.catalina.core.StandardService.start(StandardService.java:525)

                      at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

                      at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

                      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:597)

                      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

                      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

            Caused by: java.lang.NullPointerException

                      at org.jbpm.persistence.JpaProcessPersistenceContext.getProcessInstancesWaitingForEvent(JpaProcessPersistenceContext.java:35)

                      at org.jbpm.persistence.processinstance.JPASignalManager.getProcessInstancesForEvent(JPASignalManager.java:40)

                      at org.jbpm.persistence.processinstance.JPASignalManager.signalEvent(JPASignalManager.java:23)

                      at org.jbpm.process.instance.ProcessRuntimeImpl$2.activationCreated(ProcessRuntimeImpl.java:340)

                      at org.drools.impl.StatefulKnowledgeSessionImpl$AgendaEventListenerWrapper.activationCreated(StatefulKnowledgeSessionImpl.java:643)

                      at org.drools.event.AgendaEventSupport.fireActivationCreated(AgendaEventSupport.java:41)

                      at org.drools.common.DefaultAgenda.createActivation(DefaultAgenda.java:601)

                      at org.drools.reteoo.RuleTerminalNode.assertLeftTuple(RuleTerminalNode.java:257)

                      at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:196)

                      at org.drools.reteoo.SingleLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:145)

                      at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:154)

                      at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)

                      at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:141)

                      at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)

                      at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)

                      at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)

                      at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)

                      at org.drools.marshalling.impl.ProtobufInputMarshaller.assertHandleIntoOTN(ProtobufInputMarshaller.java:483)

                      at org.drools.marshalling.impl.ProtobufInputMarshaller.readFactHandles(ProtobufInputMarshaller.java:459)

                      at org.drools.marshalling.impl.ProtobufInputMarshaller.readSession(ProtobufInputMarshaller.java:259)

                      at org.drools.marshalling.impl.ProtobufInputMarshaller.readSession(ProtobufInputMarshaller.java:161)

                      at org.drools.marshalling.impl.ProtobufMarshaller.unmarshall(ProtobufMarshaller.java:117)

                      at org.drools.persistence.SessionMarshallingHelper.loadSnapshot(SessionMarshallingHelper.java:91)

                      ... 36 more

             

            And finally... here is a screen of the moment the JpaProcessPersistenceContextManager is initialized using the cmdScopedEntityManager which is null

             

            jpaprocesspersistenceCM.png

            • 3. Re: Null cmdScopedEntityManager during stateful session load
              Maciej Swiderski Master

              do you mange transaction your self? If not remove UT from the environment and let jbpm to handle transactions internally.

               

              HTH

              1 of 1 people found this helpful
              • 4. Re: Null cmdScopedEntityManager during stateful session load
                Bira Neto Newbie

                Unfortunately, not passing the transaction is not a good option for me as I don't want to use and have to setup jndi on a specific server (I want to abstract this issues)

                 

                What solved for me was to bypass the current JpaProcessPersistenceContextManager implementation  (which may still have a bug... I would make some tests).

                 

                I changed my environment initialization to

                 

                 

                  env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

                  env.set(EnvironmentName.TRANSACTION, ut);

                 

                  env.set(EnvironmentName.TRANSACTION_MANAGER,

                                new JtaTransactionManager( ut, null, TransactionManagerServices.getTransactionManager() ));

                 

                  env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, new JPAProcessPersistenceContextManagerPk(env));

                 

                 

                 

                On my JPAProcessPersistenceContextManagerPk (extends JpaProcessPersistenceContextManager) I overrided the current getProcessPersistenceContext to the implementation below

                 

                    public ProcessPersistenceContext getProcessPersistenceContext() {

                                   if (cmdScopedEntityManager == null) {

                                                  this.beginCommandScopedEntityManager();

                                   }

                        return new JpaProcessPersistenceContext( cmdScopedEntityManager );

                    }