9 Replies Latest reply on May 31, 2010 12:30 AM by jeevdav

    Handling process state



      This is for jBPM 4.3 and I am a newbie. I have a very basic question.


        An application  Instantiates a process  with three states A, B and C and when it is at state B waiting for a signal the application is gracefully shutdown. Now after this is it possible to find and instantiate the same process instance again. If yes can you tell me how?


      I tried to do this by using the findProcessInstanceById method. But this method returms null in this scenario. Remember that I shutdown my application so i had to create the ProcessEngine again..


      Thanks in advance,


        • 1. Re: Handling process state

          I was using the junit tests that come with jBPM 4.3. Does this have anything to do with the way the tests are set up? I tried commenting out repositoryService.deleteDeployment() lines in the test cases but it did not help

          • 2. Re: Handling process state

            Hi David,


            By default, the JbpmTestCase will clear database after each testcase.  You could restart processEngine in a method to prevent this problem.


            If this problem is still here.  Please provide a testcase which could reproduce the scenario.  So we could get more details to find out the reason.

            • 3. Re: Handling process state

              This is what i am running.

              testFindOne suceeds as expected, but testFindTwo and testFindThree fail unless all three are run together( when they are run together they use the same processengine and execution service)


              The bottom line is that findProcessInstanceById works only when the same processengine is used. But in the realworld after i recycle my application how will i be able to resume my incomplete processes?


              public class TestJBPM extends TestCase
              protected static ProcessEngine processEngine = null;

                 protected static RepositoryService repositoryService;
                 protected static ExecutionService executionService;
                 protected static ManagementService managementService;
                 protected static TaskService taskService;
                 protected static HistoryService historyService;
                 protected static IdentityService identityService;

                protected void setUp() throws Exception {
                    if (processEngine==null) {
                        processEngine = Configuration.getProcessEngine();
                        repositoryService = processEngine.get(RepositoryService.class);
                        executionService = processEngine.getExecutionService();
                        historyService = processEngine.getHistoryService();
                        managementService = processEngine.getManagementService();
                        taskService = processEngine.getTaskService();
                        identityService = processEngine.getIdentityService();
                 public void testFindOne() {
                    ProcessInstance processInstance = executionService.startProcessInstanceByKey("Proc","t");
                    System.out.println("process id  "+processInstance.getId());
                    Execution executionInA = processInstance.findActiveExecutionIn("a");

                    //processInstance = executionService.signalExecutionById(executionInA.getId());
                    processInstance = executionService.findProcessInstanceById("Proc.t");
                 public void testFindTwo() {

                    ProcessInstance processInstance = executionService.findProcessInstanceById("Proc.t");
                 public void testFindThree() {
                    ProcessInstance processInstance = executionService.findProcessInstanceById("Proc.t");



              The test process


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

              <process name="Proc" xmlns="http://jbpm.org/4.3/jpdl">
                 <start name="start1" g="121,59,48,48">
                    <transition name="to a" to="a" g="-25,-20"/>
                 <state name="a" g="107,134,92,52">
                    <transition name="to b" to="b" g="-26,-20"/>
                 <state name="b" g="111,207,92,52">
                    <transition name="to c" to="c" g="-25,-20"/>
                 <state name="c" g="118,271,92,52">
                    <transition name="to end1" to="end1" g="-45,-20"/>
                 <end name="end1" g="134,344,48,48"/>

              • 4. Re: Handling process state

                Hi David,


                There is no guaranty that method in testcase will run sequence as you expect.  So testFindTwo() and testFindThree() may be executed before testFindOne().


                And You didn't re-create processEngine for each testcase.

                • 5. Re: Handling process state

                  Hi HuiSheng,


                  I ran the test cases one by one by right clicking on the method I wanted to run and choosing "Run as junit test"  from eclipse. This ensured that they ran in the correct order. It aslo ensured that every time a new processengine is created.


                  - Jeeves

                  • 6. Re: Handling process state

                    It should run properly as soon as your process is persisted to a data base that is running regardless of your tests being executed or not. I mean that you have db server started as regular server and not in memory.


                    Could you post your hibernate config file?

                    • 7. Re: Handling process state




                      xml version="1.0" encoding="utf-8"?>



                      DOCTYPE hibernate-configuration PUBLIC


                      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"










                      <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>


                      <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>


                      <property name="hibernate.connection.url">jdbc:hsqldb:mem:.</property>


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


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


                      <property name="hibernate.hbm2ddl.auto">create-drop</property>


                      <property name="hibernate.format_sql">true</property>



                      <mapping resource="jbpm.repository.hbm.xml" />


                      <mapping resource="jbpm.execution.hbm.xml" />


                      <mapping resource="jbpm.history.hbm.xml" />


                      <mapping resource="jbpm.task.hbm.xml" />


                      <mapping resource="jbpm.identity.hbm.xml" />






                      • 8. Re: Handling process state

                        Based on your description and hibernate config file, it looks like each time you call your unit test method (starting new java process it will create new instance of in memory db, meaning that it will not contain any previously created processes.


                        I would suggest you to change hibernate config to point so already running db - just start hsqldb as regular server and then your process should be visible regardless of how many times you start your tests.

                        1 of 1 people found this helpful
                        • 9. Re: Handling process state



                          You got it right.


                          Now I have this and my test works as expected. Thank you!



                          <property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost:1701</property>