13 Replies Latest reply on Jul 25, 2011 10:49 AM by ayusman_dikshit

    JBPM 4.3 and JPA/Hibernate integration question

      In previous JBPM 4.v versions, we were using SpringConfiguration.setHibernateSessionFactory

      to share the same jpa/hibernate context of our running environment.

       

      This trick seems no more possible in last 4.3 version.

       

      Any suggestion to do similar stuff in 4.3 would be greatly appreciated.

        • 1. Re: JBPM 4.3 and JPA/Hibernate integration question
          saraswati.santanu

          Why do you need to do this? Even wih 4.2 or any other 4.x.

           

          Since you are using Spring, to configure hibernate session factory you have to create LocalSessionFactoryBean (or AnnotationSessionFactory which is a child class of LocalSessionFactoryBean, unless you have your own SessionFactory bean implementation). Now if you create a bean for SpringHelper then that should be good enough. A typical SpringHelper bean may look like this:


              <bean id="jbpmConfiguration" class="org.jbpm.pvm.internal.processengine.SpringHelper">
                  <property name="jbpmCfg">
                      <value>jbpm/jbpm.cfg.xml</value>
                  </property>
              </bean>

           

          jBPM config location will change as per you settings.

           

          SpringHelper is ApplicationContextAware. So application context will be injected there. Then it finds any bean of type LocalSessionFactoryBean from the application context. I believe searching bean of type AbstractSessionFactoryBean would have been better, but LocalSessionFactoryBean is just good enough. So you do not need to call any special method to inject SessionFactory into jBPM.

          • 2. Re: JBPM 4.3 and JPA/Hibernate integration question

            Thanks for your response Santanu.

             

            The problem is that, in JPA/Spring, we don't use a LocalSessionFactoryBean.

            Rather we rely on a LocalContainerEntityManagerFactoryBean with no knowledge of hibernate session api.

             

            The trick was to get a reference to the Underlying SessionFactory, something like:

             

            SpringConfuguration.setHibernateSessionFactory(((Session) entityManager.getDelegate()).getSessionFactory());

             

             

             

            For now, we still don't have any solution for JBPM 4.3 version   :-(

            • 3. Re: JBPM 4.3 and JPA/Hibernate integration question

              In SpringProcessEngine, the ApplicationContext loading fails on these lines with an ugly NullPointerException:

               

                    LocalSessionFactoryBean localSessionFactoryBean = springProcessEngine.get(LocalSessionFactoryBean.class);
                    Configuration hibernateConfiguration = localSessionFactoryBean.getConfiguration();


              We can't imagine a way to get back the hibernateConfiguration from a LocalContainerEntityManagerFactoryBean

               

              Ok we are doomed to stick on JBPM 3.x or JBPM 4.2 version... in wait of a native support of JPA (?); but there is no entry in jira.

              • 4. Re: JBPM 4.3 and JPA/Hibernate integration question
                kukeltje
                You could also try to contribute patches?
                • 5. Re: JBPM 4.3 and JPA/Hibernate integration question

                  Yes you are right,
                  open source spirit
                  that would be a so great chalenge for us!

                   

                  but jpa is 'usable' in previous version...
                  so why not maintain this dirty compatibility with 4.3?

                  • 6. Re: JBPM 4.3 and JPA/Hibernate integration question
                    kukeltje
                    Can you please point me to differences in spring related classes betweeen 4.2 and 4.3.. Then I can try and form an opinion
                    • 7. Re: JBPM 4.3 and JPA/Hibernate integration question
                      kukeltje

                      Oh... and:

                       

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

                      The Spring integration has started out as a community effort by        Andries Inzé.        Do note that Spring integration currently is in 'incubation', before        it is moved to the user guide.  

                       

                      bold is my emphasis.

                       

                      And the doc also states:

                       

                      Do note that incubation features are not yet considered stable (ie. there     could be major syntax or implementation changes in next versions).     
                      • 8. Re: JBPM 4.3 and JPA/Hibernate integration question

                        Hello

                         

                        I'm having the same problems as Christian stated. We are using JPA transations which worked in version 4.1 and I can't get it running in 4.3 because of the mentioned NPE.

                         

                        We also have an EntityManager and using the following configurations we provided the connection and transations manager to jBPM:

                         

                        jbpm.hibernate.cfg.xml

                        <?xml version="1.0" encoding="utf-8"?>
                        
                        <!DOCTYPE hibernate-configuration PUBLIC
                                  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
                        
                        <hibernate-configuration>
                          <session-factory>
                             <property name="hibernate.dialect">${hibernate.dialect}</property>
                             <property name="hibernate.hbm2ddl.auto">update</property>
                             <property name="hibernate.jdbc.batch_size">2000</property>
                             <property name="javax.persistence.transactionType">JTA</property>
                             <property name="hibernate.transaction.manager_lookup_class">com.softmodeler.server.persistence.SoftmodelerTransactionManagerLookup</property>
                             <property name="hibernate.connection.provider_class">com.softmodeler.server.persistence.SoftmodelerConnectionProvider</property>
                             
                             <mapping resource="jbpm.repository.hbm.xml" />
                             <mapping resource="jbpm.execution.hbm.xml" />
                             <mapping resource="jbpm.history.hbm.xml" />
                             <mapping resource="jbpm.task.hbm.xml" />
                             <mapping resource="jbpm.identity.hbm.xml" />
                          </session-factory>
                        </hibernate-configuration>
                        
                        

                        Notice the "hibernate.transaction.manager_lookup_class" and the "hibernate.connection.provider_class" properties.

                         

                        The Spring configuration looked like this, no sessionFactory bean is defined:

                             <osgi:reference id="transactionManager" interface="org.jencks.GeronimoPlatformTransactionManager"/>
                                <bean id="jbpmConfiguration" class="org.jbpm.pvm.internal.cfg.SpringConfiguration">
                                   <constructor-arg value="jbpm.cfg.xml"/>
                             </bean>
                        
                             <bean id="jbpmProcessEngine" factory-bean="jbpmConfiguration" factory-method="buildProcessEngine"/>
                             <bean id="jbpmRepositoryService" factory-bean="jbpmProcessEngine" factory-method="getRepositoryService" />
                             <bean id="jbpmExecutionService" factory-bean="jbpmProcessEngine" factory-method="getExecutionService" />
                             <bean id="jbpmTaskService" factory-bean="jbpmProcessEngine" factory-method="getTaskService" />
                        

                         

                        I tried to hack around the code to get it working, made my own SpringProcessEngine without using LocalSessionFactoryBean.

                             public static ProcessEngine create(ConfigurationImpl configuration) {
                                  MySpringProcessEngine springProcessEngine = null;
                        
                                  ApplicationContext applicationContext = null;
                        
                                  applicationContext = (ApplicationContext) configuration.getApplicationContext();
                        
                                  springProcessEngine = new MySpringProcessEngine();
                                  springProcessEngine.applicationContext = applicationContext;
                                  springProcessEngine.initializeProcessEngine(configuration);
                        
                                  // do not create session, hibernate configuration is set in jbpm.cfg.xml
                        
                                  springProcessEngine.checkDb(configuration);
                        
                                  return springProcessEngine;
                             }
                        

                         

                        Well now I'm getting a different NPE, jBPM is trying to access org.springframework.transaction.PlatformTransactionManager, but I'm using org.apache.geronimo.transaction.manager.GeronimoTransactionManager.

                        What would be the correct way to hock in my TransationManager?

                         

                        greets and thanks

                        • 9. Re: JBPM 4.3 and JPA/Hibernate integration question
                          mymacin

                          Is there any way to integrate with JPA ?

                           

                           

                          Thanks In Advance

                          • 10. Re: JBPM 4.3 and JPA/Hibernate integration question

                            Should I do further investigation to get this issue going?

                             

                            Should I add a Jira issue?

                            • 11. Re: JBPM 4.3 and JPA/Hibernate integration question
                              unsavory

                              I have been able to get jBPM 4.3 to play nicely with Spring and a container managed JPA persistence unit.  The trick is in giving jBPM the LocalSessionFactoryBean that is requires, while letting spring inject the container managed persistence unit throughout your application code.

                               

                              I wrote about it in more detail here:  http://captaincaveman.posterous.com/jbpm-43-spring-3-jboss-jpa-jta-configuration

                              • 12. Re: JBPM 4.3 and JPA/Hibernate integration question
                                mymacin

                                Thanks you very much Caine Lai.

                                 

                                I am looking for this solution from last two weeks and I hope this will give some oxygen for us.

                                • 13. Re: JBPM 4.3 and JPA/Hibernate integration question
                                  ayusman_dikshit

                                  @Caine Lai

                                  I used this for jbpm 4.4 and had no luck yet :-(

                                  My jbpm hanler classes simply can not get the entitymanager reference and fail with an NPE all the time

                                   

                                  Any help on this?

                                   

                                  Thanks,

                                  Ayusman