6 Replies Latest reply on Nov 2, 2005 9:49 PM by Alejandro Guizar

    jBPM and HttpSession

    Ashwini Kumar Newbie

      I need to use jBPM in a web application. I get a task list in one page and then submit the task in the next page.

      This means I am using the TaskInstance Object created in one page within another page.

      The jbpm session that created this TaskInstance object cannot be closed till it is actually used. That means that the JBPMSession object needs to be put on the HTTPSession object.

      But JBPMSession object is not serializable and therefore, proabably it was not designed to be put on the HTTPSession object.

      Can anybody give me some suggestions about what can be put into the HTTPSession so that the task created in one page can be executed in another?

      Thanks,

        • 1. Re: jBPM and HttpSession
          Andy Yeung Newbie

          You get the task in 1 page. save the task instance Id in session.
          Then use pSession.getTaskMgmtSession().loadTaskInstance(pTaskInstanceId) to get back the task instance.

          • 2. Re: jBPM and HttpSession
            Ashwini Kumar Newbie

            Hi,
            I can get back the taskInstance object without any problems. But when we go to actually execute that task, it needs the session that created this taskInstance in the first place.

            How do we put this jBPMSession object in the HTTPSession when it is not serializable? The problem is only with this JBPMSession object.

            Thanks.

            • 3. Re: jBPM and HttpSession
              Julian Klein Newbie

              You should create a new JbpmSession object. There is no need to use the original session that created the TaskInstance. It is much like a database conncetion, you do not keep it open across multiple requests nor do you put it in the HttpSession.

              Regards,
              Julian

              • 4. Re: jBPM and HttpSession
                Ashwini Kumar Newbie

                I have verified this several times before. Please look at the code below.

                JbpmSession session = jbpmSessionFactory.openJbpmSession();
                tasks = sa.getTaskInstances (session, "davids-fl-state");
                session.close();

                JbpmSession session1 = jbpmSessionFactory.openJbpmSession();
                iter = tasks.iterator();
                while (iter.hasNext())
                {
                sa.SubmitStateEnrollmentApproval("davids-fl-state", session1, (TaskInstance)iter.next());
                }

                So, I am creating the tasks with one session and executing them with another session. I get the exception below.


                Exception in thread "main" 16:37:38,873 ERROR LazyInitializationException : failed to lazily initialize a collection of role: org.jbpm.taskmgmt.def.Task.events - no session or session was closed
                org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.jbpm.taskmgmt.def.Task.events - no session or session was closed
                at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
                at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
                at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
                at org.hibernate.collection.PersistentMap.get(PersistentMap.java:123)
                at org.jbpm.graph.def.GraphElement.getEvent(GraphElement.java:52)
                at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:144)
                at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:133)
                at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:318)
                at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:293)

                ------------------
                IF I do not close the session as in the code above, I still get an exception
                -------------------

                16:50:24,287 ERROR GraphSession : org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
                Exception in thread "main" java.lang.RuntimeException: couldn't save process instance 'org.jbpm.graph.exe.ProcessInstance@74f5a4bc'
                at org.jbpm.db.GraphSession.saveProcessInstance(GraphSession.java:209)
                at EnrollmentTest.SubmitStateEnrollmentApproval(EnrollmentTest.java:205)
                at EnrollmentTest.main(EnrollmentTest.java:338)
                ----------------------------------

                There is quite certainly some relationship between a task and the session that created it. The task seeems to keep a reference to the session that created it. This makes the design of a web application fairly complicated due to having to store JbpmSession in HttpSession.

                Thanks and regards,


                • 6. Re: jBPM and HttpSession
                  Alejandro Guizar Master

                  Effectively, a persistent object is bound to the session that loaded or saved it. To use it in a different session, you must reattach the object. See section 12.3.3 Detached objects of the Hibernate users guide for a description.
                  Note that an object cannot be attached to more than one session. In order for this solution to work, the original session must be closed.