4 Replies Latest reply on Oct 17, 2006 8:32 PM by Jed Danner

    Task Not Being Created?

    Jed Danner Newbie

      I've been banging my head on this one and would like someone else (if they have some time) to take a look...

      I've been using jBPM for general process and have just recently being trying to use some of the tasks. I've run into a problem and not sure why.

      Basically, the problem I'm having is when I use a process definition from the database I can't get a task to be created. I can see the task node hit but no task is created. Using a process defintiion from a test case I can create a process and the task is created. Here are the two different methods of creating the same task:

       /** Creates a test process using the coded definition */
       public void startTestProcess()
       {
       logger.info("Starting Test Process via Coded Definition");
      
       // Create a test process definition
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
       "<process-definition name='the baby process'>" +
       " <start-state name='start'>" +
       " <transition name='baby cries' to='t'/>" +
       " </start-state>" +
       " <task-node name='t'>" +
       " <task name='change nappy'>" +
       " <assignment class='com.ider.Process.NappyAssignmentHandler'/>" +
       " </task>" +
       " <transition to='end'/>" +
       " </task-node>" +
       " <end-state name='end'/>" +
       "</process-definition>"
       );
      
       // Create the process
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
      
       // Signal the root token
       Token token = processInstance.getRootToken();
       token.signal();
      
       logger.info("Token Node: " + token.getNode());
      
       }
      
      
       /** Creates a new process based on a process definition name */
       public void startNewProcess(String processName)
       {
       JbpmContext jbpmContext = (JbpmConfigurationStatic.jbpmConfiguration).createJbpmContext();
       try {
       logger.info("Starting Process via Definition [" + processName + "]");
      
       // Load a process definition from the database
       ProcessDefinition myDef = jbpmContext.getGraphSession().findLatestProcessDefinition(processName);
      
       // Create the process
       ProcessInstance newProcess = new ProcessInstance(myDef);
      
       // Signal the root token
       Token token = newProcess.getRootToken();
       token.signal();
      
       logger.info("Token Node: " + token.getNode());
      
       jbpmContext.save(newProcess);
      
       } finally {
       jbpmContext.close();
       }
       }
      


      One called right after another yields the following logs:

      
      processAdmin.startTestProcess();
      processAdmin.startNewProcess("Test");
      
      



      Created via Coded Definition:
      -----------------------------
      18:03:37,875 INFO [UserAdminScreen] Starting Test Process via Coded Definition
      18:03:37,875 DEBUG [GraphElement] event 'process-start' on 'ProcessDefinition(the baby process)' for 'Token(/)'
      18:03:37,875 DEBUG [GraphElement] event 'before-signal' on 'StartState(start)' for 'Token(/)'
      18:03:37,875 DEBUG [GraphElement] event 'node-leave' on 'StartState(start)' for 'Token(/)'
      18:03:37,890 DEBUG [GraphElement] event 'transition' on 'Transition(baby cries)' for 'Token(/)'
      18:03:37,890 DEBUG [GraphElement] event 'node-enter' on 'TaskNode(t)' for 'Token(/)'
      18:03:37,890 DEBUG [GraphElement] event 'task-create' on 'Task(change nappy)' for 'Token(/)'
      18:03:37,890 DEBUG [GraphElement] event 'task-assign' on 'Task(change nappy)' for 'Token(/)'
      18:03:37,890 DEBUG [GraphElement] event 'after-signal' on 'StartState(start)' for 'Token(/)'
      18:03:37,890 INFO [UserAdminScreen] Token Node: TaskNode(t)


      Created via DB Definition:
      --------------------------
      18:03:41,015 INFO [UserAdminScreen] Starting Process via Definition [Test]
      18:03:41,015 DEBUG [DbPersistenceServiceFactory] creating persistence service
      18:03:41,015 DEBUG [DbPersistenceService] creating hibernate session
      18:03:41,015 DEBUG [DbPersistenceService] beginning hibernate transaction
      18:03:41,015 DEBUG [GraphElement] event 'process-start' on 'ProcessDefinition(Test)' for 'Token(/)'
      18:03:41,015 DEBUG [GraphElement] event 'before-signal' on 'StartState(start)' for 'Token(/)'
      18:03:41,015 DEBUG [GraphElement] event 'node-leave' on 'StartState(start)' for 'Token(/)'
      18:03:41,031 DEBUG [GraphElement] event 'transition' on 'Transition(baby cries)' for 'Token(/)'
      18:03:41,031 DEBUG [GraphElement] event 'node-enter' on 'TaskNode(t)' for 'Token(/)'
      18:03:41,031 DEBUG [GraphElement] event 'node-leave' on 'TaskNode(t)' for 'Token(/)'
      18:03:41,031 DEBUG [GraphElement] event 'transition' on 'Transition(248adb)' for 'Token(/)'
      18:03:41,031 DEBUG [GraphElement] event 'node-enter' on 'EndState(end)' for 'Token(/)'
      18:03:41,031 DEBUG [GraphElement] event 'process-end' on 'ProcessDefinition(Test)' for 'Token(/)'
      18:03:41,031 DEBUG [GraphElement] event 'after-signal' on 'StartState(start)' for 'Token(/)'
      18:03:41,031 INFO [UserAdminScreen] Token Node: EndState(end)


      I see in the log where the coded definition creates the task but the definition from the db skips over. I just deployed the process to the database, it looks like the coded one:

      <process-definition xmlns="" name="Test">
       <start-state name="start">
       <transition name="baby cries" to="t"/>
       </start-state>
       <task-node name="t">
       <task name="change nappy">
       <assignment class="com.ider.Process.NappyAssignmentHandler"/>
       </task>
       <transition to="end"/>
       </task-node>
       <end-state name="end"/>
      </process-definition>
      


      btw, the NappyAssignmentHandler is straight from the examples.

      Clearly, I've done something wrong...anyone care to take a guess?


      Thanks in advance for any help!

        • 1. Re: Task Not Being Created?
          Jed Danner Newbie

          It may or may not be useful to note but this is jBPM v3.1.2 running in the starter kit JBoss app server w/ database backend of MySQL Server v5.0.

          • 2. Re: Task Not Being Created?
            Konstantin Kolev Newbie

            Hi!
            Why do you call

            jbpmContext.save(newProcess);
            ?
            I think that when you close the context Hibernate wil take care of putting the right stuff in the database.
            Are you sure your code goes through the assignment handler?
            Another approach is telling the node not to create task as setting its attribute
            create-tasks='false'
            and use node-enter event of the task node to create you task. Although I think this is not what you want try this and see what happens,

            Saviola

            • 3. Re: Task Not Being Created?
              Jed Danner Newbie

              No, the AssignmentHandler isn't being called when I use the process from the database. I added some logging to the assignment handler and it looks like it's only called once the task is trying to be created. Here's the log from the two methods being run:

              10:24:06,281 INFO [UserAdminScreen] Starting Test Process via Coded Definition
              10:24:06,281 DEBUG [GraphElement] event 'process-start' on 'ProcessDefinition(the baby process)' for 'Token(/)'
              10:24:06,296 DEBUG [GraphElement] event 'before-signal' on 'StartState(start)' for 'Token(/)'
              10:24:06,296 DEBUG [GraphElement] event 'node-leave' on 'StartState(start)' for 'Token(/)'
              10:24:06,296 DEBUG [GraphElement] event 'transition' on 'Transition(baby cries)' for 'Token(/)'
              10:24:06,296 DEBUG [GraphElement] event 'node-enter' on 'TaskNode(t)' for 'Token(/)'
              10:24:06,296 DEBUG [GraphElement] event 'task-create' on 'Task(change nappy)' for 'Token(/)'
              10:24:06,296 INFO [NappyAssignmentHandler] <-------------- Setting Actor ID in NappyAssignmentHandler
              10:24:06,296 DEBUG [GraphElement] event 'task-assign' on 'Task(change nappy)' for 'Token(/)'
              10:24:06,296 INFO [NappyAssignmentHandler] --------------> DONE SETTING ACTOR
              10:24:06,296 DEBUG [GraphElement] event 'after-signal' on 'StartState(start)' for 'Token(/)'
              10:24:06,296 INFO [UserAdminScreen] Token Node: TaskNode(t)
              


              Here is the same process def loaded from the DB, but not task is created:

              10:24:08,046 DEBUG [JbpmContextInfo] creating jbpm context with service factories '[message, scheduler, logging, persist
              ence, authentication]'
              10:24:08,046 DEBUG [JbpmContext] creating JbpmContext
              10:24:08,046 INFO [UserAdminScreen] Starting Process via Definition [Test]
              10:24:08,046 DEBUG [DbPersistenceServiceFactory] creating persistence service
              10:24:08,046 DEBUG [DbPersistenceService] creating hibernate session
              10:24:08,046 DEBUG [DbPersistenceService] beginning hibernate transaction
              10:24:08,062 DEBUG [GraphElement] event 'process-start' on 'ProcessDefinition(Test)' for 'Token(/)'
              10:24:08,062 DEBUG [GraphElement] event 'before-signal' on 'StartState(start)' for 'Token(/)'
              10:24:08,062 DEBUG [GraphElement] event 'node-leave' on 'StartState(start)' for 'Token(/)'
              10:24:08,062 DEBUG [GraphElement] event 'transition' on 'Transition(baby cries)' for 'Token(/)'
              10:24:08,078 DEBUG [GraphElement] event 'node-enter' on 'TaskNode(t)' for 'Token(/)'
              10:24:08,078 DEBUG [GraphElement] event 'node-leave' on 'TaskNode(t)' for 'Token(/)'
              10:24:08,078 DEBUG [GraphElement] event 'transition' on 'Transition(1281264)' for 'Token(/)'
              10:24:08,078 DEBUG [GraphElement] event 'node-enter' on 'EndState(end)' for 'Token(/)'
              10:24:08,078 DEBUG [GraphElement] event 'process-end' on 'ProcessDefinition(Test)' for 'Token(/)'
              10:24:08,078 DEBUG [GraphElement] event 'after-signal' on 'StartState(start)' for 'Token(/)'
              10:24:08,078 INFO [UserAdminScreen] Token Node: EndState(end)
              


              Is there any other reason that the task wouldn't be created? Does anyone else have this problem?

              • 4. Re: Task Not Being Created?
                Jed Danner Newbie

                I've figured it out. Maybe this will help someone else. I did some additional looking into the process as loaded. Here's the code I used:

                 // Load a process definition from the database
                 ProcessDefinition myDef = jbpmContext.getGraphSession().findLatestProcessDefinition(processName);
                
                 // Create the process
                 ProcessInstance newProcess = new ProcessInstance(myDef);
                
                 // Signal the root token
                 Token token = newProcess.getRootToken();
                 logger.info("Root Token: " + token.getNode());
                
                 Vector nodes = new Vector(myDef.getNodes());
                
                 for (int i = 0; i < nodes.size(); i++)
                 {
                 Object test = nodes.get(i);
                 logger.info("Type: " + test.getClass().getName());
                
                 if (test.getClass().getName().equalsIgnoreCase("org.jbpm.graph.node.TaskNode"))
                 {
                 TaskNode myNode = (TaskNode)test;
                 logger.info("Are we creating tasks? " + myNode.getCreateTasks());
                 }
                 }
                
                



                The result of getCreateTasks() is 'false'. This is a problem as it should be 'true'. I tracked it down to a problem with the MySQL driver version I was using (3.0.9) vs. a newer version available - which also happens to be bundled in the jbpm starter kit. The updated MySQL driver version 3.1.7 works and my tasks are being created now.

                Oh joy. Well, hope this helps someone else.

                The following links are related to the MySQL Version I have 5.0.22 and Hibernate:

                http://opensource.atlassian.com/projects/hibernate/browse/HBX-729