13 Replies Latest reply on May 7, 2010 10:29 PM by rebody

    JBPM4.3 Variable History

    egycator

           Hello All,

      I am developing an application that integrates with jBPM4.3 and I am facing a Variable History problem ,that all variables of any completed process instance are deleted.

      From JIRA I found that there is a configuration that I can declare the variable and enable its history but it is not documented yet. Issue#2506.

      Can I know how can I declare variables and enable its history?

      If the history feature is not yet implemented , Will it be released with the next jBPM release ?

      Kindly if it will be released in the next release , What will be the release  date of JBPM 4.4 as I will depend on this date in my application plan ?

        • 1. Re: JBPM4.3 Variable History
          rebody

          Hi Khaled:

            If you want to keep history variable, you can try public void createVariable(String key, Object value, String typeName, boolean isHistoryEnabled), this method can used in ExecutionImpl.

          • 2. Re: JBPM4.3 Variable History
            egycator
            Hi Huisheng
            I tried the method you mentioned in the ExecutionImpl but I didn't know how to commit the Execution.
            My Test is :
            processInstance = executionService.startProcessInstanceByKey("Normal");
            ((ExecutionImpl)processInstance).createVariable("test", "valuetest","string",true);
            Nothing is created in the DB
            What about the Service APIs , No APIs to enable the variable history ?
            Any news about the next jBPM release 4.4 ?
            • 3. Re: JBPM4.3 Variable History
              rebody

              Hi Khaled,

                If you want to store the created variable, you should put the codes into transaction. So Whether you open a Environment or put all of function into a Command.

               

                open environment:

               

              EnvironmentImpl environment = ((EnvironmentFactory) processEngine).openEnvironment();

              try {

                // create variable

              } finally {

                  environment.close();
              }

               

                using Command:

               

              processEngine.execute(new Command() {

                  public Object execute(Environment env) {

                      // create variable
                  }

              });

               

                Furthermore, if you let spring to manage the transaction for jBPM4, you needn't do like above.

              • 4. Re: JBPM4.3 Variable History
                egycator

                Hi Huisheng

                When I used your proposed solution  as following :

                ProcessInstance processInstance = executionService.startProcessInstanceByKey("Normal");
                 
                EnvironmentImpl environment =  ((EnvironmentFactory)processEngine).openEnvironment();
                ((ExecutionImpl)processInstance).createVariable("test", "valuetest","string",true);
                Session session = environment.get(Session.class);
                Transaction tx  = session.beginTransaction();
                session.update(processInstance);
                tx.commit();
                environment.close();
                

                 

                it throws a NullPointerException

                15:27:28,703 SEV | [BaseJbpmTestCase] TEST THROWS EXCEPTION: null
                java.lang.NullPointerException
                     at org.jbpm.pvm.internal.history.events.VariableUpdate.process(VariableUpdate.java:48)
                     at org.jbpm.pvm.internal.history.HistorySessionImpl.process(HistorySessionImpl.java:31)
                     at org.jbpm.pvm.internal.history.HistoryEvent.fire(HistoryEvent.java:62)
                     at org.jbpm.pvm.internal.history.HistoryEvent.fire(HistoryEvent.java:52)
                     at org.jbpm.pvm.internal.type.Variable.setValue(Variable.java:97)
                     at org.jbpm.pvm.internal.model.ScopeInstanceImpl.createVariableObject(ScopeInstanceImpl.java:140)
                     at org.jbpm.pvm.internal.model.ScopeInstanceImpl.createVariable(ScopeInstanceImpl.java:90)
                     at com.asset.jupiter.jbpm.processes.Normal.NormalTest.testCreateProcessInstance(NormalTest.java:33)
                     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 junit.framework.TestCase.runTest(TestCase.java:164)
                     at org.jbpm.test.BaseJbpmTestCase.runTest(BaseJbpmTestCase.java:80)
                     at junit.framework.TestCase.runBare(TestCase.java:130)
                     at junit.framework.TestResult$1.protect(TestResult.java:106)
                     at junit.framework.TestResult.runProtected(TestResult.java:124)
                     at junit.framework.TestResult.run(TestResult.java:109)
                     at junit.framework.TestCase.run(TestCase.java:120)
                     at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
                     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)
                
                

                but when I use it with "isHistoryEnabled" = false , the variable is persisted.

                • 5. Re: JBPM4.3 Variable History
                  rebody

                  Hi Khaled,

                    I am so sorry for my mistake.

                   

                    There is a bug in ExecutionImpl.createVariable(), it will always throw a NullPointerException because of not checking the unsaved history variable.

                  • 6. Re: JBPM4.3 Variable History
                    egycator

                    Thanks Huisheng for trying to help

                    Any news about fixing this bug in the next version 4.4?

                    • 7. Re: JBPM4.3 Variable History
                      rebody

                      Hi Khaled,

                        There is another way you could try

                       

                       processEngine.execute(new Command() {
                                       public Object execute(Environment env) {
                                           executionImpl.createVariable("test", "valuetest",
                                               "string", false);
                      
                                          Variable variable =  executionImpl.getVariableObject(
                                                   "test");
                                           HistoryEvent.fire(new VariableCreate(variable));
                      
                                          return null;
                                       }
                                   });
                      

                       

                         I think the history variable of jBPM4 is so weak. If you want to store some history variable for process instance, you should use your own table.

                      • 8. Re: JBPM4.3 Variable History
                        sebastian.s

                        Is this documented somewhere in JIRA enabling the developers to fix this?

                        • 9. Re: JBPM4.3 Variable History
                          rebody

                          Hi Sebastian,

                            I have created a issue here.

                          https://jira.jboss.org/jira/browse/JBPM-2840

                          • 10. Re: JBPM4.3 Variable History
                            mihai007

                            After reading this, I managed to use the code snipped below, but now I don't know if it works, at least it does not give any error, but how can I get the history variables from a HistoryProcessInstance?

                             

                                                Variable variable =  executionImpl.getVariableObject(
                                                         "test");
                                                 HistoryEvent.fire(new VariableCreate(variable));



                            • 11. Re: JBPM4.3 Variable History
                              rebody

                              Hi Dan,

                                Because jBPM 4 did not implement variable history yet,  so there is no api for query HistoryVariable.  We have to use hibernate to do these query. like this:

                               

                              Session session = env.get(Session.class);
                              List list = session.createQuery("from HistoryVariableImpl").list();
                              

                               

                                Actually, there is no interface for HistoryVariableImpl. It seems we should create another JIRA issue for that.

                              • 12. Re: JBPM4.3 Variable History
                                mihai007

                                Thank you,it works without problems.

                                 

                                Now I only want to ask if is there a way to store non String variables, like a small arrayList or a map for example?

                                From what I saw, the variable is a blob type but when using VariableCreate or Update, it asks for the text value of the Variable which for a blob is null. It seems that this is the value that goes into history, so is it possible somehow to save other non string values or at least to let me serialize the object into byte[] and then to base64 before sending to history?

                                • 13. Re: JBPM4.3 Variable History
                                  rebody

                                  Hi Dan,

                                    You could create a issue for this scenario.  Now we are focusing on fixing bugs.  Maybe we could discuss this later.  This scenario is depended by some other issues about variable and history variable.

                                   

                                    Thank you very much.