1 2 Previous Next 18 Replies Latest reply on Aug 2, 2007 6:25 AM by Ronald van Kuijk

    when i end the TaskInstance,an LazyInitializationException o

    zhang baoquan Newbie

      first,i want say sorry ,because i'm a Chinese and english isn't well.
      i think you can know the folowing language:
      when i do this:

      RndfReport businessReport = new RndfReport();
       businessReport.setExampleName(example_name);
       businessReport.setExampleRemark(example_remark);
      
       JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
       JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
       Session hsession = jbpmContext.getSessionFactory().openSession();
       Transaction transaction = hsession.beginTransaction();
       try {
      
       hsession.save(businessReport);
       transaction.commit();
       ProcessDefinition pd = jbpmContext.getGraphSession().findLatestProcessDefinition("RNDFProcess");
       ProcessInstance pi = pd.createProcessInstance();
       pi.getContextInstance().setVariable("username", from_username);
       TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();
       ti.setVariable("report_id", businessReport.getReportId());
       ti.end();
       } catch (Exception e) {
       System.out.println("Unknown error in the SaveGo().");
       return_code = Property.SQL_ERROR;
       message = "?????????";
       event_type = "";
       e.getMessage();
       e.printStackTrace();
       transaction.rollback();
       }finally{
       hsession.close();
       jbpmContext.close();
       }

      exception:
      15:06:16,671 [http8001-Processor25] ERROR LazyInitializationException : failed to lazily initialize a collection of role: org.jbpm.graph.def.Node.leavingTransitions, no session or session was closed
      org.hibernate.LazyInitializationException: 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(AbstractPersistentCollection.java:358)
       at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
       at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97)
       at org.hibernate.collection.PersistentList.size(PersistentList.java:91)
       at org.jbpm.graph.def.Node.getDefaultLeavingTransition(Node.java:217)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:147)
       at org.jbpm.graph.def.Node$$EnhancerByCGLIB$$57ae0d8c.getDefaultLeavingTransition(<generated>)
       at org.jbpm.graph.exe.Token.signal(Token.java:136)
       at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:475)
       at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:389)
       at buesiness.BusinessEngine.SaveGo(BusinessEngine.java:119)
       at buesiness.BusinessEngine.exectue(BusinessEngine.java:63)
       at org.apache.jsp.order_005fexec_jsp._jspService(order_005fexec_jsp.java:99)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
       at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
       at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:209)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:670)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:517)
       at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:575)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
       at java.lang.Thread.run(Thread.java:595)

      thank you !!!!!

        • 1. Re: when i end the TaskInstance,an LazyInitializationExcepti
          Vt Ysh Newbie

          I think you get this exception, because you do so

          transaction.commit();


          If you got this transaction from jbpmContext session you've done wrong. If you need rollback transaction just use jbpmContext.setRollbackOnly() method and transaction will be rolled back on close() method.

          • 2. Re: when i end the TaskInstance,an LazyInitializationExcepti
            zhang baoquan Newbie

            Thank you vtysh!!
            But when delete "transaction.commit();" and try again,The same exception still throwed.

            • 3. Re: when i end the TaskInstance,an LazyInitializationExcepti
              Vt Ysh Newbie

              Remove all manual actions with transactions and sessions

              Session hsession = jbpmContext.getSessionFactory().openSession();
               Transaction transaction = hsession.beginTransaction();


              transaction.rollback();



              hsession.close();


              If you need to save some hibernate object use session from this method
              jbpmContext.getSession()

              • 4. Re: when i end the TaskInstance,an LazyInitializationExcepti
                zhang baoquan Newbie

                Hi,vtysh
                you are so warmhearted,I'm so sorry for asking you three times.
                Why don't you go to sleep?:)
                As you say,I modified the code like this:

                JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
                 JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
                 Session hsession = jbpmContext.getSession();
                 try {
                 hsession.save(businessReport);
                 ProcessDefinition pd = jbpmContext.getGraphSession().findLatestProcessDefinition("RNDFProcess");
                 ProcessInstance pi = pd.createProcessInstance();
                 //pi.getContextInstance().setVariable("username", from_username);
                 TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();
                 ti.setVariable("report_id", businessReport.getReportId());
                 ti.end();
                 } catch (Exception e) {
                 System.out.println("Unknown error in the SaveGo().");
                 return_code = Property.SQL_ERROR;
                 message = "?????????";
                 event_type = "";
                 e.getMessage();
                 e.printStackTrace();
                 jbpmContext.setRollbackOnly();
                 }finally{
                 jbpmContext.close();
                 }

                But it's throws exception all the time

                • 5. Re: when i end the TaskInstance,an LazyInitializationExcepti
                  Vt Ysh Newbie

                  Try to save process instance after creation and before the task ending

                  TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();
                  jbpmContext.save(pi);
                  


                  If it will not help, try to close jbpmContext after creation of start task instance and create new one (jbpmContext). Then retrieve already created taskInstance by id and try to process it.

                  About why i am not sleeping, because we are in different time zones and i have a day now.

                  • 6. Re: when i end the TaskInstance,an LazyInitializationExcepti
                    zhang baoquan Newbie

                    Thank you with all my words

                    TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();
                    jbpmContext.save(pi);//there is :org.hibernate.SessionException: Session is closed

                    when i close jbpmContext,it will throw the same exception(org.hibernate.SessionException: Session is)

                    • 7. Re: when i end the TaskInstance,an LazyInitializationExcepti
                      Vt Ysh Newbie

                      You should close context after save operation

                      • 8. Re: when i end the TaskInstance,an LazyInitializationExcepti
                        zhang baoquan Newbie

                        Before save operation ,I never close context.see this:

                        try {
                         hsession.save(businessReport);
                         ProcessDefinition pd = jbpmContext.getGraphSession().findLatestProcessDefinition("RNDFProcess");
                         ProcessInstance pi = pd.createProcessInstance();
                         //pi.getContextInstance().setVariable("username", from_username);
                         TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();
                         jbpmContext.close();
                         ti.setVariable("report_id", businessReport.getReportId());
                         ti.end();
                         } catch (Exception e) {
                         System.out.println("Unknown error in the SaveGo().");
                         return_code = Property.SQL_ERROR;
                         message = "?????????";
                         event_type = "";
                         e.getMessage();
                         e.printStackTrace();
                         jbpmContext.setRollbackOnly();
                         }finally{
                         jbpmContext.close();
                         }


                        • 9. Re: when i end the TaskInstance,an LazyInitializationExcepti
                          zhang baoquan Newbie

                          I mean that ,After create the TaskInstance

                          TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();

                          Whether i save ti or close jbpmcontext ,the same exception always throwed.
                          09:27:24,765 [http8001-Processor25] ERROR DbPersistenceService : hibernate commit failed
                          org.hibernate.SessionException: Session is closed
                           at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:116)
                           at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
                           at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
                           at org.jbpm.persistence.db.DbPersistenceService.commit(DbPersistenceService.java:253)
                           at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:211)
                           at org.jbpm.svc.Services.close(Services.java:222)
                           at org.jbpm.JbpmContext.close(JbpmContext.java:139)
                           at buesiness.BusinessEngine.SaveGo(BusinessEngine.java:113)
                           at buesiness.BusinessEngine.exectue(BusinessEngine.java:62)
                           at org.apache.jsp.order_005fexec_jsp._jspService(order_005fexec_jsp.java:99)
                           at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
                           at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
                           at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
                           at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
                           at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
                           at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
                           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
                           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
                           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
                           at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
                           at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
                           at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
                           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
                           at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
                           at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
                           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
                           at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
                           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
                           at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
                           at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
                           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
                           at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
                           at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
                           at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
                           at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:209)
                           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:670)
                           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:517)
                           at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:575)
                           at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
                           at java.lang.Thread.run(Thread.java:595)
                          


                          • 10. Re: when i end the TaskInstance,an LazyInitializationExcepti
                            zhang baoquan Newbie

                            Sorry,I forgot the log

                            09:36:53,328 [http8001-Processor22] DEBUG JbpmContextInfo : creating jbpm context with service factories '[tx, message, scheduler, logging, persistence, authentication]'
                            09:36:53,328 [http8001-Processor22] DEBUG JbpmContext : creating org.jbpm.JbpmContext@1ddf47e
                            09:36:53,328 [http8001-Processor22] DEBUG DbPersistenceServiceFactory : creating persistence service
                            09:36:53,328 [http8001-Processor22] DEBUG DbPersistenceService : creating hibernate session
                            09:36:53,343 [http8001-Processor22] DEBUG DbPersistenceService : beginning hibernate transaction
                            Hibernate:
                             select
                             rndf_s_report.nextval
                             from
                             dual
                            Hibernate:
                             /* named HQL query GraphSession.findLatestProcessDefinitionQuery */ select
                             *
                             from
                             ( select
                             processdef0_.ID_ as ID1_4_,
                             processdef0_.NAME_ as NAME3_4_,
                             processdef0_.DESCRIPTION_ as DESCRIPT4_4_,
                             processdef0_.VERSION_ as VERSION5_4_,
                             processdef0_.ISTERMINATIONIMPLICIT_ as ISTERMIN6_4_,
                             processdef0_.STARTSTATE_ as STARTSTATE7_4_
                             from
                             JBPM_PROCESSDEFINITION processdef0_
                             where
                             processdef0_.NAME_=?
                             order by
                             processdef0_.VERSION_ desc )
                             where
                             rownum <= ?
                            Hibernate:
                             select
                             hibernate_sequence.nextval
                             from
                             dual
                            Hibernate:
                             select
                             hibernate_sequence.nextval
                             from
                             dual
                            09:36:53,359 [http8001-Processor22] DEBUG GraphElement : event 'process-start' on 'ProcessDefinition(RNDFProcess)' for 'Token(/)'
                            09:36:53,359 [http8001-Processor22] WARN StatefulPersistenceContext : Narrowing proxy to class org.jbpm.graph.node.StartState - this operation breaks ==
                            Hibernate:
                             select
                             hibernate_sequence.nextval
                             from
                             dual
                            09:36:53,375 [http8001-Processor22] DEBUG TaskController : creating task instance variable 'report_id' from process variable 'report_id', value 'null'
                            09:36:53,375 [http8001-Processor22] DEBUG VariableContainer : create variable 'report_id' in 'TaskInstance[appendForm]' with value 'null'
                            09:36:53,375 [http8001-Processor22] DEBUG GraphElement : event 'task-create' on 'Task(appendForm)' for 'Token(/)'
                            Hibernate:
                             select
                             hibernate_sequence.nextval
                             from
                             dual
                            Hibernate:
                             select
                             hibernate_sequence.nextval
                             from
                             dual
                            Hibernate:
                             select
                             hibernate_sequence.nextval
                             from
                             dual
                            Hibernate:
                             /*
                            FROM
                             RndfVUserinfo
                            WHERE
                             group_fid LIKE '102220100%' */ select
                             rndfvuseri0_.USERNAME as USERNAME32_,
                             rndfvuseri0_.PASSWORD as PASSWORD32_,
                             rndfvuseri0_.TRUENAME as TRUENAME32_,
                             rndfvuseri0_.COMPANY as COMPANY32_,
                             rndfvuseri0_.DEPARTMENT as DEPARTMENT32_,
                             rndfvuseri0_.DUTY as DUTY32_,
                             rndfvuseri0_.TELEPHONE as TELEPHONE32_,
                             rndfvuseri0_.EMAIL as EMAIL32_,
                             rndfvuseri0_.HANDSET as HANDSET32_,
                             rndfvuseri0_.GROUP_NAME as GROUP10_32_,
                             rndfvuseri0_.GROUP_DESCRIPTION as GROUP11_32_,
                             rndfvuseri0_.GROUP_SID as GROUP12_32_,
                             rndfvuseri0_.GROUP_FID as GROUP13_32_,
                             rndfvuseri0_.SEARCH_LEVEL as SEARCH14_32_,
                             rndfvuseri0_.LEVELS as LEVELS32_
                             from
                             WLSRNDF.RNDF_V_USERINFO rndfvuseri0_
                             where
                             group_fid like '102220100%'
                            09:36:56,203 [http8001-Processor22] DEBUG GraphElement : event 'task-assign' on 'Task(appendForm)' for 'Token(/)'
                            09:36:56,203 [http8001-Processor22] DEBUG JbpmContext : closing JbpmContext
                            09:36:56,203 [http8001-Processor22] DEBUG Services : closing service 'persistence': org.jbpm.persistence.db.DbPersistenceService@9d478b
                            09:36:56,203 [http8001-Processor22] DEBUG DbPersistenceService : committing hibernate transaction
                            09:36:56,203 [http8001-Processor22] ERROR DbPersistenceService : hibernate commit failed


                            • 11. Re: when i end the TaskInstance,an LazyInitializationExcepti
                              Vt Ysh Newbie

                              Try to debug this piece of code starting with some simple action gradually adding all other lines to see which code is broke your application. But it looks very strange, that after any write operation you get jbpmContext autoclose. Maybe something is wrong in hibernate or jbpm configuration? Do you use standart one, or some specific? And do you use last jbpm 3.2.1?

                              About closing context after creating process instance, i meant this

                               ProcessInstance pi = pd.createProcessInstance();
                               TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();
                               long id=ti.getId();
                               jbpmContext.save(pi);
                               jbpmContext.close();
                               jbpmContext=jbpmConfiguration.createJbpmContext();
                               ti=jbpmContext.getTaskMgmtSession().loadTaskInstance(id);
                              


                              • 12. Re: when i end the TaskInstance,an LazyInitializationExcepti
                                zhang baoquan Newbie

                                You are so kindly! thank you!
                                I'm not sure if my wording is right,Sorry!
                                I debug the code you wrote,The same exception(org.hibernate.SessionException: Session is closed!) was threw at this line:

                                jbpmContext.save(pi);

                                My jbpm version is 3.2GA and use default(jbpm.cfg.xml is null) config files except the following code in hibernate.cfg.xml
                                <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
                                
                                 <!-- JDBC connection properties (begin) -->
                                 <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
                                 <property name="hibernate.connection.url">jdbc:hsqldb:mem:jbpm</property>
                                 <property name="hibernate.connection.username">sa</property>
                                 <property name="hibernate.connection.password"></property>
                                 <!-- JDBC connection properties (end) -->
                                
                                 <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
                                

                                I'll have a try use jbpm3.2.1 version to debug same code.
                                I can never thank you enough for your help.

                                • 13. Re: when i end the TaskInstance,an LazyInitializationExcepti
                                  zhang baoquan Newbie

                                  sorry , I send the wrong hibernate.cfg.xml

                                   <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
                                  
                                   <!-- JDBC connection properties (begin) -->
                                   <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
                                   <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:zbq</property>
                                   <property name="hibernate.connection.username">wlsrndf</property>
                                   <property name="hibernate.connection.password">wlsrndf</property>
                                   <!-- JDBC connection properties (end) -->
                                  
                                   <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
                                  


                                  • 14. Re: when i end the TaskInstance,an LazyInitializationExcepti
                                    Vt Ysh Newbie

                                    I don't know, maybe it is an oracle problem. Try to search forum i saw some topics where users describe theirs problems with oracle environment.
                                    My proposition is to start from simple code open and close context. Then add ProcessInstance creation, then add other parts of code... Also you can try your code with default hypersonic datasource to be sure, that problem is not in source.

                                    1 2 Previous Next