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

    hibernate.LazyInitializationException with jBPM websale exam

    derjohannes

      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

        • 1. Re: hibernate.LazyInitializationException with jBPM websale
          kukeltje

          You say exactely 'like' the jbpm webapp (the websale is just a process IN the webapp). Did you develop something yourself?

          (re) opening the hibernate session happens automagically in the webapp on each post to the server by filters configured in web.xml (jbpmcontexfilter). So i'd start looking there and compare it to what you did yourself

          • 2. Re: hibernate.LazyInitializationException with jBPM websale
            derjohannes

            This was exactly the point, thank you!!! I wouldn't have figured this out alone...

            On task.jsp, i added a commons-fileupload field:

            <h:form id="form1" name="form1" enctype="multipart/form-data" >
            [...]
            <t:inputFileUpload id="fileupload"
            accept="application/pdf"
            value="#{taskBean.upFile}"
            storage="file"
            styleClass="fileUploadInput"
            required="false" />[...]

            to make this work, i had to add the following to web.xml:


            <filter-name>multipartFilter</filter-name> <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>

            <filter-mapping>
            <filter-name>multipartFilter</filter-name>
            <url-pattern>/*</url-pattern>
            </filter-mapping

            Can you give me a hint how I can make both work, jBPM/Hibernate and commons-FileUpload?

            • 3. Re: hibernate.LazyInitializationException with jBPM websale
              kukeltje

               

              "DerJohannes" wrote:
              This was exactly the point, thank you!!! I wouldn't have figured this out alone...


              Ahhh.. come on... I bet you would have.... I did.

              On task.jsp, i added a commons-fileupload field:

              <h:form id="form1" name="form1" enctype="multipart/form-data" >
              [...]
              <t:inputFileUpload id="fileupload"
              accept="application/pdf"
              value="#{taskBean.upFile}"
              storage="file"
              styleClass="fileUploadInput"
              required="false" />[...]

              to make this work, i had to add the following to web.xml:


              <filter-name>multipartFilter</filter-name> <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>

              <filter-mapping>
              <filter-name>multipartFilter</filter-name>
              <url-pattern>/*</url-pattern>
              </filter-mapping

              Can you give me a hint how I can make both work, jBPM/Hibernate and commons-FileUpload?



              • 4. Re: hibernate.LazyInitializationException with jBPM websale
                kukeltje

                hmmm sorry, wrong quoting and no preview done (shame on me)

                • 5. Re: hibernate.LazyInitializationException with jBPM websale
                  derjohannes

                  Oh my...

                  There must be another reason for the hibernate.LazyInitializationException:

                  I've removed everything from web.xml that i had added, i've also removed everthing from the jsps and the beans that had anything to to with commons-fileupload, but NOW, the hibernate.LazyInitializationException still occurs!

                  How can I find the root cause to this problem?

                  It's getting more and more mysterious...

                  Thank you for your help!

                  • 6. Re: hibernate.LazyInitializationException with jBPM websale
                    kukeltje

                    One thing to find te solution is to at least post a stacktrace. It's difficult to help at all if we have no info.

                    • 7. Re: hibernate.LazyInitializationException with jBPM websale
                      drenoux

                      To reproduce the problem, go the the Faces-comfig.xml and set the scope of the TaskBean to Session (instead of request)

                      Hope it helps :) at least to reproduce