2 Replies Latest reply on Jun 3, 2008 11:29 AM by jjacobwip

    Jbpm - EJB LazyInitialization Exception


      I was trying to learn jbpm and came across this scenario.

      I was trying to create a Session Facade for my Process related activities (instantiate process instance, list tasks etc). I created a basic CMP EJB and added method to instantiate a ProcessInstance which is already deployed. For testing, I am calling this EJB method from a servlet using the remote interface of the EJB.

      In my EJB method, I am creating a new instance of my business process which is already deployed. This method returns the newly created ProcessInstance. After that, in my servlet I am calling processInstance.signal()= and getting the below exception.

      18:42:12,484 ERROR [LazyInitializationException] failed to lazily initialize a collection of role: org.jbpm.graph.def.Node.leavingTransitions, no session or session was closed
      : failed to lazily initialize a collection of role: org.jbpm.graph.def.Node.leavingTransitions, no session or session was closed
      at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(
      at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(

      If I do processInstance.signal() from my EJB itself, everything is working fine.

      I do understand that its a bad design to tightly couple the servlet and the EJB layer and there could be transaction issues, but just wanted to doube confirm it.

      Thanks in advance

        • 1. Re: Jbpm - EJB LazyInitialization Exception

          I understand your problem, This is because your transaction/session is initiated in EJB and it was completed automatically when you exited the EJB method. when you call processInstance.signal() JBPM will try to use the session associated with the processInstanceobject for updatign the database. which is closed in this scenario, There are couple of ways to do this

          1) Try to complete all the database activities in one single method of EJB.

          2) If you want to do this in multiple methods/layers then you need to make these both methods in one transaction like, start a transaction before calling the EJB object and end the transaction in your servelet or calling class after completing the process.
          Spring has certain API to support thsi functionality,i implemented this in spiring but i am not sure how you will do it in EJB.


          • 2. Re: Jbpm - EJB LazyInitialization Exception

            Thank you!! You are right, its working fine when I do all the operations in EJB itself. Also I saw in another thread that Lazy initialization of hibernate is not supported across layers especially in a Servlet - EJB scenario.

            Thanks again!!