4 Replies Latest reply on Sep 10, 2005 1:54 PM by julian_k

    How to Create Task without Process Instance?

    kukeltje

      why would you like to create a task that is not bound to any process? I can imagine you'd like to create runtime task, not predefined, but tasks outside of a process?

        • 1. Re: How to Create Task without Process Instance?
          tom.baeyens

          jbpm is designed for supporting tasks that are not related to a process. that is never tested though.

          ronald, it can be usefull to have 1 centralized tasklist for many applications. so that the tasks of other applications show up in one UI. (it would have to be a custom UI cause jbpm webapp can't generate links to other apps for the non-jbpm task instances)

          TaskInstance taskInstance = new TaskInstance();
          taskInstance.setActorId("you");
          taskInstance.set...
          jbpmSession.getSession().save(taskInstance);

          regards, tom.

          • 2. Re: How to Create Task without Process Instance?
            julian_k

            Tom,

            I tried as you suggested and it does not seem to persist to the database. Here is my code and debug output. I don't see any errors, but would appreciate your input. I also tried this without adding a Task to the TaskInstance.

            Thanks,
            Julian

             TaskInstance taskInstance = new TaskInstance();
             taskInstance.setName(taskName);
             Task task = new Task();
             task.setDescription(taskDescription);
             task.setName(taskName);
             task.setPriority(Integer.parseInt(taskPriority));
             taskInstance.setTask(task);
             taskInstance.setActorId(actorId);
            
             Long longValue = jbmpSession.getSession().save(taskInstance);
             jbpmSession.close();
            

            2005-09-08 23:56:45,091 [http-8080-Processor23] DEBUG org.hibernate.impl.SessionImpl.<init> at line 250 - opened session at timestamp: 4613071688052736
            2005-09-08 23:56:45,101 [http-8080-Processor23] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient at line 159 - saving transient instance
            2005-09-08 23:56:45,101 [http-8080-Processor23] DEBUG org.hibernate.jdbc.AbstractBatcher.logOpenPreparedStatement at line 290 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
            2005-09-08 23:56:45,101 [http-8080-Processor23] DEBUG org.hibernate.jdbc.ConnectionManager.openConnection at line 296 - opening JDBC connection
            2005-09-08 23:56:45,101 [http-8080-Processor23] DEBUG org.hibernate.SQL.log at line 324 - select nextval ('hibernate_sequence')
            Hibernate: select nextval ('hibernate_sequence')
            2005-09-08 23:56:45,101 [http-8080-Processor23] DEBUG org.hibernate.jdbc.AbstractBatcher.getPreparedStatement at line 378 - preparing statement
            2005-09-08 23:56:45,111 [http-8080-Processor23] DEBUG org.hibernate.id.SequenceGenerator.generate at line 87 - Sequence identifier generated: 77
            2005-09-08 23:56:45,111 [http-8080-Processor23] DEBUG org.hibernate.jdbc.AbstractBatcher.logClosePreparedStatement at line 298 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
            2005-09-08 23:56:45,111 [http-8080-Processor23] DEBUG org.hibernate.jdbc.AbstractBatcher.closePreparedStatement at line 416 - closing statement
            2005-09-08 23:56:45,111 [http-8080-Processor23] DEBUG org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId at line 100 - generated identifier: 77, using strategy: org.hibernate.id.SequenceGenerator
            2005-09-08 23:56:45,111 [http-8080-Processor23] DEBUG org.hibernate.event.def.AbstractSaveEventListener.performSave at line 133 - saving [org.jbpm.taskmgmt.exe.TaskInstance#77]
            2005-09-08 23:56:45,111 [http-8080-Processor23] DEBUG org.hibernate.engine.Cascades.cascade at line 836 - processing cascade ACTION_SAVE_UPDATE for: org.jbpm.taskmgmt.exe.TaskInstance
            2005-09-08 23:56:45,111 [http-8080-Processor23] DEBUG org.hibernate.engine.Cascades.cascade at line 861 - done processing cascade ACTION_SAVE_UPDATE for: org.jbpm.taskmgmt.exe.TaskInstance
            2005-09-08 23:56:45,131 [http-8080-Processor23] DEBUG org.hibernate.engine.Cascades.isUnsaved at line 526 - id unsaved-value: 0
            2005-09-08 23:56:45,141 [http-8080-Processor23] DEBUG org.hibernate.engine.Cascades.cascade at line 836 - processing cascade ACTION_SAVE_UPDATE for: org.jbpm.taskmgmt.exe.TaskInstance
            2005-09-08 23:56:45,141 [http-8080-Processor23] DEBUG org.hibernate.engine.Cascades.cascade at line 861 - done processing cascade ACTION_SAVE_UPDATE for: org.jbpm.taskmgmt.exe.TaskInstance
            2005-09-08 23:56:45,151 [http-8080-Processor23] DEBUG org.hibernate.impl.SessionImpl.close at line 269 - closing session
            2005-09-08 23:56:45,151 [http-8080-Processor23] DEBUG org.hibernate.jdbc.ConnectionManager.closeConnection at line 317 - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
            2005-09-08 23:56:45,151 [http-8080-Processor23] DEBUG org.hibernate.jdbc.JDBCContext.afterTransactionCompletion at line 283 - after transaction completion
            2005-09-08 23:56:45,151 [http-8080-Processor23] DEBUG org.hibernate.impl.SessionImpl.afterTransactionCompletion at line 403 - after transaction completion


            • 3. Re: How to Create Task without Process Instance?
              tom.baeyens

              i have added this test to the org.jbpm.taskmgmt.exe.TaskInstanceDbTest and it seems to work for me:

              public void testTaskInstanceUnrelatedToAProcess() {
              TaskInstance taskInstance = new TaskInstance("do laundry", "someoneelse");
              session.save(taskInstance);
              long id = taskInstance.getId();

              newTransaction();

              taskInstance = (TaskInstance) session.load(TaskInstance.class, new Long(id));
              assertNotNull(taskInstance);
              assertEquals("do laundry", taskInstance.getName());
              assertEquals("someoneelse", taskInstance.getActorId());
              }


              maybe it has to do with flushing... one thing that might help is a tip for inspecting the hsqldb database while debugging: put this string in the "Display" window and press CTRL+SHIFT D (=Display). Now the hsql database manager should appear with the data of the runtime in memory data.

              regards, tom.

              • 4. Re: How to Create Task without Process Instance?
                julian_k

                Tom,

                I have been using the Spring jBPM module, and it appears that the problem is with transactions. I am not sure at this point if it is my spring xml configs or the code itself. Either way, I can verify that this code works b/c I programatically opened a Hibernate Transaction and flushed it, after which all was working as expected. Thanks for the help!

                Regards,
                Julian