5 Replies Latest reply on Jun 9, 2008 6:18 PM by Ronald van Kuijk

    How Continue Process Execution Using Java (Without the jBPM

    Felipe Fornachari Newbie

      Hello everybody!

      I think that my doubt is a little confuse, I'll try to explain best possible.

      I have a test process, created with jBPM 3.2.2, and I want to execute it without the jBPM console.
      It's a very simple process, just to learn more about jBPM.
      There are two Task-Nodes, the first node is assigned to the actor "user". The user make a requisition, typing his name in a field and typing his requisition in another field, then press the button "Submit". After that, the process go to the second task-node, assigned for the actor "admin". The admin read the user's name and the user's requisition. Then the admin type some information in a field called "Admin's Comment" and click in the button "OK", then the process go to the end state and finish.

      I tested my process in the jBPM Console and everything works well, but I would like to run the process in my own JSP page, without the jBPM console.
      I can start the process and execute the first task with java implementation, like below:

      JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseResource("default.jbpm.cfg.xml");
      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
      GraphSession gpSession = jbpmContext.getGraphSession();
      
      ProcessDefinition pdef = gpSession.findLatestProcessDefinition("MyProcessName");
      ProcessInstance instance = pdef.createProcessInstance();
      
      //set initial values
      instance.getContextInstance().setVariable("userName", "John");
      instance.getContextInstance().setVariable("requisition", "John's Requisition");
      
      Token token = instance.getRootToken();
      token.signal();
      
      jbpmContext.close();


      The code above works well, I can start my process and execute the first task. But, what kind of java implementation I have to do to continue the execution, to execute the next task?

      Any help, any idea?
      Thank in advance!

        • 1. Re: How Continue Process Execution Using Java (Without the j
          Ananth Sreepathi Newbie

          If you have two task nodes after the first signal your first start taskinstance would start automatically.Now to got o next tasskinstance I.e Admin task,
          You get the taskinstances of user,do your custom code and then signal/end the user taskinstance to got to admin taskistance. then you get the admin task instance and signal it to to go to end.

          For more help Refer examples for more detail.

          Thanks

          • 2. Re: How Continue Process Execution Using Java (Without the j
            Felipe Fornachari Newbie

            Hi sreepathis, thank you very much for your reply.
            I am trying what you said, and I find some information in the internet.
            I am doing like below, but without success:

            JbpmContext ctx = JbpmConfiguration.getInstance().createJbpmContext();
            GraphSession graphSession = ctx.getGraphSession();
            
            //8 is the id of my process instance
            ProcessInstance processInstance = graphSession.loadProcessInstance(8);
            
            Collection taskList = null;
            taskList = (Collection) processInstance.getTaskMgmtInstance().getTaskInstances();
            taskList.iterator().next();
            ((TaskInstance)taskList.iterator().next()).end();
            
            //set the admin's comment, like I said in my first post
            processInstance.getContextInstance().setVariable("adminComment", "Approved");


            could you help me?
            Thank you!

            • 3. Re: How Continue Process Execution Using Java (Without the j
              Ananth Sreepathi Newbie

              If you are not getting any error then you are doing right and you should have completed task 1 with the code you posted.now you repeat the same process for the task2
              and the process instance will be completed then.

              Collection taskList = null;
              taskList = (Collection) processInstance.getTaskMgmtInstance().getTaskInstances();
              taskList.iterator().next();
              ((TaskInstance)taskList.iterator().next()).end();
              

              Try your luck and see.

              Thanks

              • 4. Re: How Continue Process Execution Using Java (Without the j
                Felipe Fornachari Newbie

                Sorry, sorry..
                I am working so hard here that I forget the error. When I execute the code of my last post, I receive this error:

                org.hibernate.exception.JDBCConnectionException: could not load an entity: [org.jbpm.graph.exe.Token#8]
                 at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
                 at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
                 at org.hibernate.loader.Loader.loadEntity(Loader.java:1874)
                 at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
                 at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
                 at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3042)
                 at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
                 at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
                 at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
                 at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98)
                 at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
                 at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836)
                 at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66)
                 at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
                 at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
                 at org.jbpm.graph.exe.Token$$EnhancerByCGLIB$$f23ef6ca.hashCode(<generated>)
                 at java.util.HashMap.put(Unknown Source)
                 at org.hibernate.collection.PersistentMap.readFrom(PersistentMap.java:259)
                 at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1008)
                 at org.hibernate.loader.Loader.readCollectionElements(Loader.java:646)
                 at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:591)
                 at org.hibernate.loader.Loader.doQuery(Loader.java:701)
                 at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
                 at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
                 at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
                 at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
                 at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
                 at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
                 at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
                 at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
                 at org.hibernate.collection.AbstractPersistentCollection.readIndexExistence(AbstractPersistentCollection.java:125)
                 at org.hibernate.collection.PersistentMap.containsKey(PersistentMap.java:128)
                 at org.jbpm.context.exe.ContextInstance.getTokenVariableMap(ContextInstance.java:363)
                 at org.jbpm.context.exe.ContextInstance.getVariable(ContextInstance.java:166)
                 at org.jbpm.context.exe.ContextInstance.getVariable(ContextInstance.java:156)
                 at ContinuarExecucao.main(ContinuarExecucao.java:74)
                Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
                 at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
                 at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
                 at com.microsoft.jdbc.base.BaseConnection.getImplConnection(Unknown Source)
                 at com.microsoft.jdbc.base.BaseStatement.setupImplConnection(Unknown Source)
                 at com.microsoft.jdbc.base.BaseStatement.<init>(Unknown Source)
                 at com.microsoft.jdbc.base.BasePreparedStatement.<init>(Unknown Source)
                 at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
                 at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
                 at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
                 at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
                 at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
                 at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
                 at org.hibernate.loader.Loader.doQuery(Loader.java:673)
                 at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
                 at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
                 ... 33 more
                ----------------------------> ERROR: could not load an entity: [org.jbpm.graph.exe.Token#8]
                


                Any help would be appreciate!
                Thank you again!

                • 5. Re: How Continue Process Execution Using Java (Without the j
                  Ronald van Kuijk Master

                  look at the many, many testcases on how to use the jbpm API. For your last question, you probably have to search the hibernate forum and then get back here....