3 Replies Latest reply on Sep 12, 2006 9:19 AM by Jitendra Singh

    saving own objects with Hibernate in jbpm

    Jerome BATON Newbie

      Hi all,

      I have custom objects that I have added to the jbpm schema.
      Those objects are hibernatable. My app is multithreaded.

      What is the prefered way to save the custom objects ?

      When I get the hibernate session from a newly created jbpmcontext, I get an exception like this

      org.jbpm.JbpmException: closed JbpmContext in different order then they were created... check your t
      ry-finally's around JbpmContexts blocks


      Using something like this in my main class ,
      public static synchronized JbpmContext getPersistenceContext() {
       if(JbpmContext.getCurrentJbpmContext()!=null)
       return JbpmContext.getCurrentJbpmContext();
       else
       return instanceConfigurationJbpm.createJbpmContext() ;
       }
      

      , I get an NPE on a Criteria.list() call based on a Session obtained via getPersistenceContexte().getSession

      java.lang.NullPointerException
       at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:442)
       at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:368)
       at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
       at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
       at org.hibernate.loader.Loader.doQuery(Loader.java:661)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
       at org.hibernate.loader.Loader.doList(Loader.java:2150)
       at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
       at org.hibernate.loader.Loader.list(Loader.java:2024)
       at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
       at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1492)
       at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
      ......
      


      What is the best practise to save one's own objects ?


      Thanks


      Jerome



        • 1. Re: saving own objects with Hibernate in jbpm
          Jitendra Singh Newbie

          Heyi Jerome,

          Can you explain a bit more as to where you are using the custom objects? Is it custom module instance or custom objects stored in context instance .. or is it custom nodes ??

          have a look at this :
          http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3970268#3970268

          cheers!

          • 2. Re: saving own objects with Hibernate in jbpm
            Jerome BATON Newbie

            Hi jits_1998,

            As an example, my principal custom object has, amongst its fields, a long that is an id of a jbpm process instance.

            This custom object is saved in DB by Hibernate through a regular session while the jbpm process instance is saved using a jbpmcontext.

            The hib. session is obtained from the same configuration as jbpm, for having the (few) tables in the same schema is not an issue.

            public static Session createPersistantSession() {
            DbPersistenceServiceFactory dbPersistenceServiceFactory = (DbPersistenceServiceFactory) instanceConfigurationJbpm.getServiceFactory("persistence");
             return dbPersistenceServiceFactory.getSessionFactory().openSession() ;
            }
            


            Right now, the issue in the post above is not anymore but I am facing a new one about contexts closed more than once

            I'm using version 3.2

            11:11:03,653 [Thread-3] ERROR DbPersistenceService : problem rolling back after failed commit
            org.hibernate.TransactionException: Transaction not successfully started
             at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:149)
             at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:166)
             at org.jbpm.svc.Services.close(Services.java:211)
             at org.jbpm.JbpmContext.close(JbpmContext.java:139)
             at com.aspheria.cerbere.Workflow.run(Workflow.java:515)
             at java.lang.Thread.run(Thread.java:534)
            11:11:03,653 [Thread-3] ERROR Services : problem closing service 'persistence'
            org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session
             at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:172)
             at org.jbpm.svc.Services.close(Services.java:211)
             at org.jbpm.JbpmContext.close(JbpmContext.java:139)
             at com.xxxx.cerbere.Workflow.run(Workflow.java:515)
             at java.lang.Thread.run(Thread.java:534)
            Caused by: org.hibernate.TransactionException: Transaction not successfully started
             at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)
             at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:162)
             ... 4 more
            
             ... 4 more
            org.jbpm.JbpmException: closed JbpmContext more then once... check your try-finally's around JbpmContexts blocks
             at org.jbpm.JbpmConfiguration.popJbpmContext(JbpmConfiguration.java:521)
             at org.jbpm.JbpmConfiguration.jbpmContextClosed(JbpmConfiguration.java:537)
             at org.jbpm.JbpmContext.close(JbpmContext.java:144)
             at com.xxxx.cerbere.Workflow.run(Workflow.java:515)
             at java.lang.Thread.run(Thread.java:534)
            


            Thanks for your help

            JBaton


            • 3. Re: saving own objects with Hibernate in jbpm
              Jitendra Singh Newbie

              Is your problem similar to this?

              http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971000#3971000

              I think it is. Lets wait for a solution from someone on this.

              I am also just a couple of weeks old jBPM user.

              cheers!