7 Replies Latest reply on Oct 18, 2006 6:47 AM by David Renoux

    hibernate.LazyInitializationException with jBPM websale exam

    Johannes Mueller Newbie

      Hello,

      I get the quoted error when I try to access jBPM taskInstances, like "taskInstance.setVariable" or "jbpmContext.save(taskInstance)".

      I know that this is due to a closed Hibernate session. But I don't know why the session is closed and how to control that.

      The situation is as follows:
      I extended the jBPM Starters Kit websale example; the structure of the jsps and the backing beans is still the same.

      First, the user is on home.jsp and sees a list of "latest process instances". When he chooses one, the backing bean "HomeBean.java" runs the method "startProcessInstance" before it returns the navigation string "task" to the JavaServer Faces context. In HomeBean.startProcessInstance everything is working fine. The commands
      - long processDefinitionId = JsfHelper.getId("processDefinitionId");
      - ProcessDefinition processDefinition = graphSession.loadProcessDefinition(processDefinitionId);
      - ProcessInstance processInstance = new ProcessInstance(processDefinition);
      - TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();
      - jbpmContext.save(processInstance);
      - taskBean.initialize(taskInstance);
      are executed without problems.

      On task.jsp, the process graph is correctly displayed by the tag
      <jbpm:processimage task="${taskBean.taskInstanceId}" />

      As you can see, everthing is okay up to this point.

      But...when I hit "Save & Close" now, the TaskBean.saveAndClose method is called (exactly like in the jBPM Starters Kit websale example). TaskBean.saveAndClose calls TaskBean.save and as soon as this method tries to run the command
      - taskInstance.setVariable
      - or jbpmContext.save(taskInstance),

      I get the following error:

      09:42:34,441 ERROR [LazyInitializationException] 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:56)
      at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
      at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
      at org.jbpm.taskmgmt.exe.TaskInstance$$EnhancerByCGLIB$$1cd1f5d7.getTaskMgmtInstance()
      at org.jbpm.JbpmContext.save(JbpmContext.java:297)

      Can you please tell me what could be the reason for that? Who told Hibernate to close the session? When? Why? How can I prevent Hibernate from closing the session? How can I reopen it? Or could there be another reason for this error?

      I am searching for the cause since two days but haven't found it yet; i'm kind of stuck.

      Any help would be appreciated,

      Johannes