7 Replies Latest reply on Jan 7, 2009 10:33 PM by Ronald van Kuijk

    Problem persisting tasks

    Fernando Luis Newbie

      Hi, first of all I want to say that I checked the forum, but I didn't find anything to solve my doubt.

      Intro:
      I'm creating the process definition in a programmatic way. I create the ProcessDefinition, then the process Instances, and then I create the tasks dinamically. To create the tasks I have an event "node enter" and createTask = false in the NodeTask.

      This is the ActionHandler I use to create the tasks: (I just put the important code)

      public void execute(ExecutionContext executionContext) throws Exception {
      JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
      
      TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();
       TaskNode nodeApproval = (TaskNode)executionContext.getNode();
      //get the only task definited in the processDefinition
      Task task = (Task)nodeApproval.getTasks().iterator().next();
      //taskNumber and user are variables
      //I instantiate for example 3 task
      for (int i=0; i<tasksNumber; i++){
       TaskInstance newTaskInstance= tmi.createTaskInstance(task, executionContext.getToken());
       newTaskInstance.setActorId(user);
      //THIS IS THE LINE that is not working
      jbpmContext.getSession().save(newTaskInstance);
      
       }
      

      I have to put that line because if I don't put, the task instance does not save the actor. But the problem is that even if I instance three tasks it only saves one.
      If I do this, with an xml (not programmatically) work well.

      I had to use
      jbpmContext.getSession().save(newTaskInstance);
      and not jbpmContext.save( ..); because if I use this one on the close it gives me "object references an unsaved transient instance" exception

      any idea, clue?
      Thanks
      Fernando




        • 1. Re: Problem persisting tasks
          Fernando Luis Newbie

          Does the TaskNode.addTask(task) method works well?
          I'm printing my process definition to check if is well builded and everything appears well excepts the tasks that don't appear!
          Any idea why they don't appear? Probably this is why is not working programmatically and yes with the xml defintion

          I'm using JpdlXmlWriter.toString(pd); . I know is deprecated, but is just to check if the process definition defined programmatically was well builded

          thanks

          • 2. Re: Problem persisting tasks
            Ronald van Kuijk Master

            why do you create a new context in the actionhandler?

            and with TaskNode.addTask you change the processdefinition, not adding additional tasks to the running instance

            • 3. Re: Problem persisting tasks
              Fernando Luis Newbie

               

              why do you create a new context in the actionhandler?

              Because I'm a newby and believe me that documentation does not help.
              How is should I do in my example?

              and with TaskNode.addTask you change the processdefinition, not adding additional tasks to the running instance


              I 'm doing TaskNode.addTask Before create the process instance, when I building the process definition.

              Thanks for your help kukeltje!, any help or clue is welcome


              • 4. Re: Problem persisting tasks
                Ronald van Kuijk Master

                Nowhere in the docs, examples etc.. it is mentioned that you should create a context... None of the examples you can find in the source do this.... I've not heard anybody do it... so I *don't* think the docs are the problem here..

                and

                I had to use
                jbpmContext.getSession().save(newTaskInstance);
                and not jbpmContext.save( ..); because if I use this one on the close it gives me "object references an unsaved transient instance" exception
                will probably disappear if you remove the additional context

                I'm doing TaskNode.addTask Before create the process instance, when I building the process definition.
                But that is something totally different from what you do on your initial post

                • 5. Re: Problem persisting tasks
                  Ronald van Kuijk Master

                  In addition to my first statement... that is about creating contexts IN an actionhandler

                  • 6. Re: Problem persisting tasks
                    Fernando Luis Newbie

                    I tried what you suggested me, but it did not work.

                    I finally could solve my problems with transient object exception, saving explicitly through Hibernate Session:

                    jbpmContext.getSession().save(executionContext.getTaskMgmtInstance());
                    or

                    jbpmContext.getSession().save(contextInstance);

                    depending on the case.
                    I don't know if this is right, but at least worked. I saw one post from a guy who had the same problem when deployed the process programmatically, so that's why I post my solution
                    Thanks!
                    Fernando.

                    • 7. Re: Problem persisting tasks
                      Ronald van Kuijk Master

                      thanks for reporting back...