2 Replies Latest reply on Jul 21, 2010 7:15 AM by spiga

    Lazy loading of sub-process

    spiga

      Hi all,

      I have a problem in getting a subprocess reference from the main process instance.

      My code is the following:

       

      ProcessInstance processInstance = executionService.startProcessInstanceByKey("RPG");
      ExecutionImpl ex_pi = ((ExecutionImpl) processInstance).findActiveExecutionIn("integr_doc");
      ProcessInstance sub_pi = ex_pi.getSubProcessInstance();   
      assertNotNull(sub_pi);

       

      where "integr_doc" is the name of a subprocess

       

      The call to "getSubProcessInstance()" is succesful, but the object "sub_pi" throws an Exception if I try to read any property of it because it was lazy initialized and the session has been closed.

       

      I get the following exception:

       

      org.hibernate.LazyInitializationException <init>
      GRAVE: could not initialize proxy - no Session
      org.hibernate.LazyInitializationException: could not initialize proxy - no Session

       

      In order to resolve this problem, I have found only one solution: modifying the "jbpm.execution.hbm.xml" in "jbpm.jar" by adding the attribute "lazy=false" to the foreign-key "FK_EXEC_SUBPI".

      This is a very awful solution because I had to modify the original library!

      If I put a copy of "jbpm.execution.hbm.xml" in the classpath (in order to not modify the original library), JBoss AS try to map jBPM entity beans before the related classes are loaded, so it fails to start.

       

      Is there a way to get a subprocess instance more gracefully?

       

      Thank you in advance and sorry for my long thread...

       

      Fabio

        • 1. Re: Lazy loading of sub-process
          mwohlf

          did you try executing your code within a command like described in this thread:

           

          processEngine.execute(new Command() {
              public Object execute(Environment env) {
                  // do your stuff here
                  return null;
              }
          });

           

          or open/close an environment like described in the docs ?

           

          Doing so should take care of the hibernate session and prevent LazyInitializationExceptions

          • 2. Re: Lazy loading of sub-process
            spiga

            Thank you very much Michael,

            within the command my method works well!

             

            Bye,

            Fabio