5 Replies Latest reply on Aug 11, 2010 9:42 PM by HuiSheng Xu

    JBPM 4.3 or 4.4 and LocalContainerEntityManagerFactoryBean

    Joe Schmoe Newbie

      Has anyone had any success at all using JBPM 4.3 or 4.4 with a LocalContainerEntityManagerFactoryBean instead of a LocalSessionFactoryBean? 

       

      I would like to use Spring's JPATransactionManager (NOT JTA) with a LocalContainerEntityManagerFactoryBean, but jBPM's SpringProcessContext assumes the use of a LocalSessionFactoryBean and HibernateTransactionManager.

       

      Any pointers or tips on how to get this to work?  Or is it just not possible?

        • 1. Re: JBPM 4.3 or 4.4 and LocalContainerEntityManagerFactoryBean
          HuiSheng Xu Master

          Hi Caine,

           

          I am not familiar with JPA.  So I don't know how to use LocalContainerEntityManagerFactoryBean to replace LocalSessionFactoryBean.  Could LocalContainerEntityManagerFactoryBean use hibernate's *.hbm.xml to mapping entity class?

           

          The key point is the jbpm4 using org.hibernate.Session to access Database,  So I am afraid at this moment, we couldn't use JPA directly.  Maybe someone could provide a JPA DbSession implementation to achieve this feature.

           

          For the TransactionManager issue, I think we could use the PlatformTransactionManager which was provided by spring,  You could refer Developer Guide to get more information about how to integrate spring and jbpm-4.x

           

          http://docs.jboss.com/jbpm/v4/devguide/html_single/#springIntegration

          • 2. Re: JBPM 4.3 or 4.4 and LocalContainerEntityManagerFactoryBean
            Joe Schmoe Newbie

            Hi HuiSheng,

             

            I appreciate the response.  Here's the thing.  The real problem lies in that JBPM assumes you are using a LocalSessionFactoryBean and specifically looks for one with the Spring configuration.

             

            However, it is possible to retrieve the underlying hibernate session factory from Spring's LocalContainerEntityManagerFactoryBean.  It's just that JBPM does not support this because it assumes you are using a LocalSessionFactoryBean.

             

            I understand that JBPM needs to use hibernate and is using the org.hibernate.Session to access the database, but what I don't understand is why it requires the use of the Spring LocalSessionFactoryBean, when there are multiple other ways of configuring a hibernate session factory.

             

            I saw some old forum posts about the ability to inject the session factory into the JBPM context using the session-factory attribute in jbpm.config.xml, but again it does not work because it is not of type LocalSessionFactoryBean.

             

            This is a serious issue for anyone using JPA.  It basically means if you are using JPA you cannot use JBPM without resorting to some major hacking.  It is a shame that JBPM has chosen to abandon JPA users as this is the Java spec!  It's fine if JBPM wishes to use hibernate underneath, but there should at least be some way of providing the hibernate session to JBPM from the JPA entitymanager.

            • 3. Re: JBPM 4.3 or 4.4 and LocalContainerEntityManagerFactoryBean
              HuiSheng Xu Master

              Hi Caine,

               

              Could you tell me how to get org.hibernate.Session from EntityManager?  If it is possible,  we could make a bridge from EntityManager to jbpm.  Thank you very much.

              • 4. Re: JBPM 4.3 or 4.4 and LocalContainerEntityManagerFactoryBean
                Joe Schmoe Newbie

                Hi HuiSheng,

                 

                Thanks again for your help!

                 

                if you wish to get the hibernate session factory from the EntityManagerFactory using Java code, you would do:

                 

                public static SessionFactory getSessionFactory(EntityManagerFactory emf) {
                      if (emf == null) {
                         return null;
                      }
                      HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory) emf;
                      return hemf.getSessionFactory();
                   }

                 

                However, in Spring it is easy to retrieve a sessionFactory from the underlying entitymanagerfactory like so:

                 

                 

                <!-- JPA EntityManagerFactory -->
                <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                        <property name="dataSource" ref="dataSource" />
                          <property name="jpaVendorAdapter">
                             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                 <property name="showSql" value="${jpa.showSql}" />
                                 <property name="database" value="${jpa.database}" />
                             </bean>
                        </property>
                        <property name="jpaDialect">
                             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
                        </property>
                     ....
                </bean>
                 
                <!-- Hibernate Session Factory -->
                <bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory" />
                
                
                

                 

                The sesssion factory returned by this method will be of type org.hibernate.HibernateSessionFactory.

                 

                Does this help?