1 Reply Latest reply on Sep 20, 2007 5:11 AM by David Roberts

    get processinstance with task id

    clause Mbacky Newbie

      hi every body,
      i want to get a processinstance by using a task id,
      i am using:

      public ProcessInstance getProcessInstance(String taskId){
       jbpmContext=jbpmConfiguration.createJbpmContext();
       try{
       taskInstance=this.getTaskinstanceByID(taskId);
       processInstance=taskInstance.getTaskMgmtInstance().getProcessInstance();
       System.out.println("\n id processinstance: "+processInstance.getId());
      // processInstance=graphSession.getProcessInstance(processInst.getId());
       }catch(Exception exception){exception.printStackTrace();}
       finally{
       jbpmContext.close();
       }
       return processInstance;
       }
      


      where :

      public TaskInstance getTaskinstanceByID(String taskInstanceId){
       try{
       jbpmContext=jbpmConfiguration.createJbpmContext();
       taskInstance = jbpmContext.getTaskInstance(Long.parseLong(taskInstanceId));
       }finally{
       jbpmContext.close();
       }
       return taskInstance;
       }
      


      there is an error when it execute:
      processInstance=taskInstance.getTaskMgmtInstance().getProcessInstance();
      


      error is:

      GRAVE: could not initialize proxy - the owning Session was closed
      org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
       at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
       at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
       at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
       at org.jbpm.taskmgmt.exe.TaskMgmtInstance$$EnhancerByCGLIB$$6d252382.getProcessInstance(<generated>)
       at com.savoi.business.TaskBusiness.getProcessInstance(TaskBusiness.java:80)
       at com.savoi.actions.ValidateAction.performAction(ValidateAction.java:48)
       at com.savoi.actions.BaseAction.execute(BaseAction.java:17)
       at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
       at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
       at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
       at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
       at java.lang.Thread.run(Unknown Source)
      
      




        • 1. Re: get processinstance with task id
          David Roberts Apprentice

          The call jbpmContext.close() closes the "owning session".

          Both your methods as using the "jbpmContext" variable.

          So, when you call the method getTaskinstanceByID(String taskInstanceId), it calls jbpmContext.close() in your finally block. This closes the session. Now remember, your "jbpmContext" is shared by both methods, so when your getProcessInstance(String taskId) method tries to call taskInstance.getTaskMgmtInstance().getProcessInstance(), the session is already closed.

          Try changing your getTaskinstanceByID method to this:

          public TaskInstance getTaskinstanceByID(String taskInstanceId){
           taskInstance = jbpmContext.getTaskInstance(Long.parseLong(taskInstanceId));
           return taskInstance;
           }
          


          As you already have a jbpmContext initialized, don't recreate it in this method.

          Hope this helps.