1 Reply Latest reply on Aug 10, 2011 2:54 PM by Gary Struthers

    rule.ConsequenceException only with JPA

    Gary Struthers Newbie

      I've adapted Salaboy's /04-jBPM5-PersistentEmergencyServiceProcess to my process and rule. I copied it's 2 process managers and jpa configuration and adapted his test class. The h2 database connection works. I made another process manager that doesn't use

      JPAKnowledgeService, it just calls kbase.newStatefulKnowledgeSession()


      My rule execute with kbase.newStatefulKnowledgeSession()


      Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.788 sec


      But with JPAKnowledgeService

      Hibernate: update ProcessInstanceInfo set lastModificationDate=?, lastReadDate=?, processId=?, processInstanceByteArray=?, startDate=?, state=?, OPTLOCK=? where InstanceId=? and OPTLOCK=?

      BEFORE ACTIVATION FIRED rule:applicationReady activationId:applicationReady [3, 2] declarations: $process=WorkflowProcessInstance1 [processId=XXX,state=1](2); $vars=FreshmanReadPIvars [XXX](3) ruleflow-group: assignApplication

      1    09/08 17:44:59,788[main] ERROR drools.persistence.SingleSessionCommandService.rollbackTransaction - Could not commit session

      org.drools.runtime.rule.ConsequenceException: rule: applicationReady


                at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)

        • 1. Re: rule.ConsequenceException only with JPA
          Gary Struthers Newbie

          I made the problem go away but I don't understand why. I have a rule that updates a field in a process variable pojo.

          rule "applicationReady"

              ruleflow-group "assignApplication"


                  $process: WorkflowProcessInstance();

                  $vars :PIvars() from (PIvars)$process.getVariable("vars");

                  eval($vars.getAppId() == 0);


              System.out.println("!!Begin firing rule applicationReady " + $vars);


          #       $process.setVariable("vars", $vars);

              System.out.println("!!End firing rule applicationReady"  + $vars);



          Commenting out $process.setVariable("vars", $vars); works with both JPA and without. My pojo is inserted as a Fact. Salaboy's example

          rule "New Ambulance for Heart Attack Emergencies"

              ruleflow-group "select_vehicle"


                  $process: WorkflowProcessInstance()

                  Emergency(type == "Heart Attack") from $process.getVariable("emergency")



                  System.out.println("A new Ambuance is being created!");

                  Ambulance ambulance = new Ambulance("MyAmbulance");

                  ((WorkflowProcessInstance)kcontext.getKnowledgeRuntime().getProcessInstance($process.getId())).setVariable("vehicle", ambulance);



          Creates a new pojo, where mine just sets a field variable and in my case I'm not sure what is the reliable way to do it.