4 Replies Latest reply on Jun 6, 2006 10:10 AM by Bill Schneider

    The same

    Ronald van Kuijk Master

      Sounds like an interesting addition to jBPM. Look in thread-local to see if there already is a Hibernate session in there and if not, create a new one. The dangerous thing is that one never knows for sure the session that is in thread-local is the one that has to be used. Maybe besides the session a variable could be set in thread local to indicate the session provided should be used. Definately sounds interesting.

      Please make a jira issue for this as an enhancement and refer to this topic.

        • 1. Re: The same
          Nick Nickolov Newbie

          I think it would be a better idea to have it directly in Hibernate - a SessionFactory whose openSession() does the thread-local caching. No changes in JBPM would be required then.

          Maybe it would be nice to have a
          JbpmSessionFactory.openSession(Session)
          method, so that you can pass the Hibernate session as a parameter. Do you think I should open a Jira issue? The downside is that one must always be careful to pass a Hibernate session when opening a JBPM session.

          • 2. Re: The same
            Tom Baeyens Master

            a JbpmSessionFactory.openSession(Session) method will be added. see jira.

            regards, tom.

            • 3. Re: The same
              Nick Nickolov Newbie

              Thanks for http://jira.jboss.com/jira/browse/JBPM-297

              In case somebody has a similar requirement - until the next release comes out, I've adopted the following solution:

              JBPM_SESSION_FACTORY = JbpmSessionFactory.buildJbpmSessionFactory(CONFIGURATION);

              becomes
              JBPM_SESSION_FACTORY = new JbpmSessionFactory(CONFIGURATION, null) {
               public JbpmSession openJbpmSession() {
               return new JbpmSession(this, HibernateManager.getThreadLocalSession());
               }
              };

              HibernateManager is our custom class doing the thread-local session caching, and all stuff related to Hibernate. CONFIGURATION is Hibernate's Configuration.

              • 4. jBPM and Hibernate thread-local session
                Bill Schneider Newbie

                I am having the same issue with jBPM 3.1.1. I looked at the JBPM-297
                (http://jira.jboss.com/jira/browse/JBPM-297) and wasn't sure if this was implemented yet or how to use it.

                The issue is that DbPersistenceService.openSession() calls SessionFactory.openSession() directly. It could instead try SessionFactory.getCurrentSession() first, as that would delegate to Hibernate's standard pluggable mechanism for binding a current threadlocal session. This would also work with Spring transaction management.

                -- Bill