1 2 Previous Next 17 Replies Latest reply on Aug 27, 2010 5:53 AM by HuiSheng Xu

    Variables from ended process ...

    Jaber C. Mourad Novice

      Hi,

       

      I looking for a solution to access to process instance variable after process end in jbpm 4.3...

       

      AFAIK, at the end of the instance, all variables are deleted !

       

      Is it possible to retain them and access them in history ?

       

      Regards

        • 1. Re: Variables from ended process ...
          HuiSheng Xu Master

          Hi Jaber,

           

          The history variable feature has not implemeneted yet in jbpm 4.3.  If you want to store history variable after proces have been deleted, you must store them into your table.

           

          Maciej have implemented this feature in the current trunk.  We could try this feature after jbpm 4 releasing.

           

          But I don't think store all of process variables is a good idea.  If you want more controlling for the variable data, please create your table and maintain them in your own tables.  Please consider about it.

          • 2. Re: Variables from ended process ...
            Jaber C. Mourad Novice

            Hi,

             

            I'm agree with out, it is not a good practice to store variables after the end of the process instance. Now Jbpm is use in my current project to replace some paper docs.

             

            Currently, my document is the process instance because all task validation are part of the document and to generate the final pdf, I'm using data from the process (task, assignee, complete date...) and variables which are populate by users.

             

            Variables are mainly used to create a file or to show them in a jsf page... and there are no other usage !

             

            Is it possible to set programmatically an event listener for a process instance ? or is jbpm 4.4 is enough stable for development usage ?

             

            Regards

            • 3. Re: Variables from ended process ...
              HuiSheng Xu Master

              Hi jaber,

               

              Is it possible to set programmatically an event listener for a process  instance ?

              Because execution didn't implement the ObservableElement interface, so we cannot set an event listener to it.  If you want to get some history event, you could use History Listener Chain.  Please refer here : http://docs.jboss.com/jbpm/v4/devguide/html_single/#d0e1169

               

              is jbpm 4.4 is enough stable for development usage ?

              Since we had resovled 90+ issues, I want to believe jbpm 4.4 is stable enough.  If you have any ideas for the next version of jbpm4, please tell us, Thank you very much.

              • 4. Re: Variables from ended process ...
                Jaber C. Mourad Novice

                Hi,

                 

                I'm trying to use history varaibles in jbpm 4.4 and I encounter an NPE :

                2010-06-17 15:56:07,742 [INFO ] org.jbpm.pvm.internal.svc.DefaultCommandService 54  - exception while executing command org.jbpm.pvm.internal.cmd.GetHistoryVariablesCmd@194d4313
                java.lang.NullPointerException
                        at org.jbpm.pvm.internal.cmd.GetHistoryVariablesCmd.execute(GetHistoryVariablesCmd.java:60)
                        at org.jbpm.pvm.internal.cmd.GetHistoryVariablesCmd.execute(GetHistoryVariablesCmd.java:40)
                        at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
                        at org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(SpringCommandCallback.java:45)
                        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
                        at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:53)
                        at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
                        at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
                        at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:56)
                        at org.jbpm.pvm.internal.svc.HistoryServiceImpl.getVariables(HistoryServiceImpl.java:97)

                 

                Is there something particular to configure to make it available ?

                 

                I'm using the executionService method executionService.createVariables(executionId, myVariables, true); to activate the history on the current process variable, is it enough ?

                 

                Regards

                • 5. Re: Variables from ended process ...
                  Maciej Swiderski Master

                  Could you provide a bit more details about how you create and how you access history variable?

                   

                  One thing that comes to my mind directly is that you shall use processInstanceId and not executionId (sometimes it is the same) to get history variables.

                  • 6. Re: Variables from ended process ...
                    Jaber C. Mourad Novice

                    Hi,

                     

                    To get history variable i'm using that code using the processInstanceId :

                          public Map<String, Object> getHistoryProcessInstanceVariable(String processInstanceId) {
                                Set<String> variableNames = historyService.getVariableNames(historyProcessInstanceId);
                                return historyService.getVariables(processInstanceId, variableNames);
                          }

                     

                    In my test :

                    HistoryProcessInstance historyProcessInstance = processInstanceService.getHistoryProcessInstanceById(processInstance.getId());
                                assertEquals(historyProcessInstance.getState(), "ended" );
                                Map<String, Object> historyVariables = processInstanceService.getHistoryProcessInstanceVariable(historyProcessInstance.getProcessInstanceId());
                                assertNotNull(historyVariables);
                                assertFalse(historyVariables.isEmpty());

                     

                    In my service, to create my variables (I change the code to be sure that I'm using the processInstanceId) :

                     

                    String processInstanceId = executionService.findProcessInstanceById(taskService.getTask(taskId).getExecutionId()).getId();
                    executionService.createVariables(processInstanceId, variables, true);

                     

                    But nothing better

                     

                    Any Idea ?

                    • 7. Re: Variables from ended process ...
                      Maciej Swiderski Master

                      Could you please provide a unit test for this?

                       

                      I have tried to reproduce it but no luck unless processInstanceId is wrong or list of variable names gives as argument to getVariables method is null.

                      • 8. Re: Variables from ended process ...
                        Jaber C. Mourad Novice

                        No pb, I will create a fresh unit test tomorrow morning (for me), perhaps I will find my misconfiguration !

                         

                        Regards

                        • 9. Re: Variables from ended process ...
                          Jaber C. Mourad Novice

                          Hi,

                           

                          I don't undersand the trouble !

                           

                          I create a test for history variable and all works as expected (including setting non history variables and variable set by some eventlistener) !

                           

                          In a real process, I've got that NPE !

                           

                          2010-06-18 15:08:27,274 [INFO ] org.jbpm.pvm.internal.svc.DefaultCommandService 54  - exception while executing command org.jbpm.pvm.internal.cmd.GetHistoryVariablesCmd@70a6aa31
                          java.lang.NullPointerException
                              at org.jbpm.pvm.internal.cmd.GetHistoryVariablesCmd.execute(GetHistoryVariablesCmd.java:65)
                              at org.jbpm.pvm.internal.cmd.GetHistoryVariablesCmd.execute(GetHistoryVariablesCmd.java:37)
                              at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
                              at org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(SpringCommandCallback.java:45)
                              at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
                              at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:49)
                              at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
                              at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
                              at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:56)
                              at org.jbpm.pvm.internal.svc.HistoryServiceImpl.getVariable(HistoryServiceImpl.java:90)

                           

                          So, I'm suspecting a missconfiguration, but I don't know where !

                           

                          Regards

                          • 10. Re: Variables from ended process ...
                            Jaber C. Mourad Novice

                            Hi,

                             

                            Finally, I manage to solve it !

                            My test method was transactional by spring aspect (using @Transactional) and all process/task/history was executing into the same transaction (which is absolutly not the normal way the process execution in my application).

                             

                            When I remove the transactional annotation, my test become green !

                             

                            I can reproduce it with any test, but I don't understand why that happen !

                             

                            If you think about an explanation, I will be happy !

                             

                            Regards

                            • 11. Re: Variables from ended process ...
                              Maciej Swiderski Master

                              Unfortunately I am not spring expert but if you post here a test case to illustrate the problem I am sure someone will take a look at it.

                              • 12. Re: Variables from ended process ...
                                HuiSheng Xu Master

                                Hi jaber,

                                 

                                I guess, If you used readOnly=true or UNSUPPORTED, then the transaction won't be committed to the database, so the process instance cannot be found later.

                                 

                                So If you could provide a whole project,  we could investigate more clearly. Thank you very much.

                                • 13. Re: Variables from ended process ...
                                  Jaber C. Mourad Novice

                                  I'm using transaction in unit test with rollbackOnly=false so, I hope it is enought to commit data

                                   

                                  I'm suspecting some conflict between transaction from test and task execution and from automatic activities (java, mail and custom)...

                                   

                                  I will try to reproduce it in a clean environment and if it does the same thing, I will send it to you.

                                   

                                  Regards

                                  • 14. Re: Variables from ended process ...
                                    Charles Aznavour Newbie

                                    Hi Jaber,

                                     

                                    we´re getting exactly the same error. We´re also using Spring integration and using transactions. We´re currently encapsulating our tests with a transaction to rollback the data later.

                                     

                                    Of course, we could rearrange our tests in another way, but I see situations in our application where we also want this transactional behavior...

                                     

                                    How do you deal with this error?

                                     

                                    Cheers,

                                    Charles

                                    1 2 Previous Next