9 Replies Latest reply on Apr 20, 2012 5:39 AM by gigazhang

    JBPM5, Spring, BTM and Tomcat

    snyperboss

      Hello All,

       

       

      Will I be able to configure JBPM5 for persistence in a web application using XA datasource configured using Spring and BTM .

      I dont want to make any changes in the tomcat configuration.

      Will I be able to do this or will I have to modify the tomcat server.xml etc?

       

      Thanks!

        • 1. Re: JBPM5, Spring, BTM and Tomcat
          calca

          Yes you should be able. Maybe this can help you

          http://docs.codehaus.org/display/BTM/Spring+Framework2x  

           

          Demian

          • 2. Re: JBPM5, Spring, BTM and Tomcat
            snyperboss

            After Googling for a while I came across this post.

             

            http://stackoverflow.com/questions/5027539/bitronix-spring-hibernate-persistence

             

            I think this might not be possible.

             

             

            What is the disadvantage of runnig JBPM5 process in non persistent mode? 

             

            Or can I configure the persistant mode  to run without a XA datasource ie without any third party Transaction manager like Bitronix.

             

             

            Another question is if my server crash and if the process was at a human task node, will it be still at the same node after a restart and would it

            be able to continue from there without a persistence configuration or will I have to start the process from the beginning?

             

             

            Thanks!

            • 3. Re: JBPM5, Spring, BTM and Tomcat
              snyperboss

              Hi All,

               

              I could Integrate this using spring in a single bean defenition file.

               

              <?xml version="1.0" encoding="UTF-8"?> 
              <beans xmlns="http://www.springframework.org/schema/beans" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 
              
              
              
              
              
                  <bean id="basicdataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
                      <property name="driverClassName"> 
                          <value>com.mysql.jdbc.Driver</value> 
                      </property> 
                      <property name="url"> 
                          <value>jdbc:mysql://localhost:3306/test</value> 
                      </property> 
                      <property name="username"> 
                          <value>root</value> 
                      </property> 
                      <property name="password"> 
                          <value>qaz@12345</value> 
                      </property> 
                  </bean> 
                  <bean id="xadataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource" 
                      init-method="init" destroy-method="close"> 
                      <property name="className" 
                          value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" /> 
                      <property name="uniqueName" value="jdbc/testDS1" /> 
                      <property name="minPoolSize" value="1" /> 
                      <property name="maxPoolSize" value="5" /> 
                      <property name="allowLocalTransactions" value="true" /> 
                      <property name="driverProperties"> 
                          <props> 
                              <prop key="URL">jdbc:mysql://localhost:3306/test</prop> 
                              <prop key="user">root</prop> 
                              <prop key="password">qaz@12345</prop> 
                          </props> 
                      </property> 
                  </bean> 
              
              
                  <bean id="txManager" 
                      class="org.springframework.transaction.jta.JtaTransactionManager"> 
                      <property name="transactionManager" ref="bitronixTransactionManager" /> 
                      <property name="userTransaction" ref="bitronixTransactionManager" /> 
                  </bean> 
              
                  <bean id="bitronixTransactionManager" factory-method="getTransactionManager" 
                      class="bitronix.tm.TransactionManagerServices" depends-on="xadataSource,txManager" 
                      destroy-method="shutdown" /> 
              
              
              
                  <bean id="entityManagerFactoryJbpmPersistanceJpa" 
                      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
                      <property name="dataSource" ref="xadataSource" /> 
                      <property name="persistenceUnitName" value="org.jbpm.persistence.jpa" /> 
                      <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /> 
                      <property name="jpaVendorAdapter"> 
                          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
                              <!-- 
                                  <property name="databasePlatform" 
                                  value="org.hibernate.dialect.MySQLDialect" /> 
                              --> 
                              <property name="databasePlatform" value="org.hibernate.dialect.SybaseDialect" /> 
                              <property name="showSql" value="true" /> 
                              <property name="generateDdl" value="false" /> 
                          </bean> 
                      </property> 
                  </bean> 
              
                  <bean id="entityManagerFactoryJbpmTask" 
                      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
                      <property name="dataSource" ref="basicdataSource" /> 
                      <property name="persistenceUnitName" value="org.jbpm.task" /> 
                      <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /> 
                      <property name="jpaVendorAdapter"> 
                          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
                              <!-- 
                                  <property name="databasePlatform" 
                                  value="org.hibernate.dialect.MySQLDialect" /> 
                              --> 
                              <property name="databasePlatform" value="org.hibernate.dialect.SybaseDialect" /> 
                              <property name="showSql" value="true" /> 
                              <property name="generateDdl" value="false" /> 
              
                          </bean> 
                      </property> 
                  </bean> 
              
              
              
                  <bean id="testInsertDAO" class="com.sample.TestInsertDAO"> 
                      <property name="dataSource" ref="basicdataSource" /> 
                  </bean> 
              
              
              
              </beans> 
              

               

               

              Thanks!

              • 4. Re: JBPM5, Spring, BTM and Tomcat
                qintao1203

                In JBPM5.1  ,  JPAKnowledgeService must be find jndi of transaction from container.

                • 5. Re: JBPM5, Spring, BTM and Tomcat
                  jbpmdev

                  Hi snyperboss ,

                   

                  This configuration helped me lot.Could you please share the complete code with us?i am new here.

                   

                  Thanks in advance

                  • 6. Re: JBPM5, Spring, BTM and Tomcat
                    snyperboss

                    Hi,

                     

                    This is how I create the session using the above spring configuration.

                     

                     

                    public static StatefulKnowledgeSession createSession() throws Exception {
                             
                            /* 
                             * Create the knowledgebase using the required bpmn and drl files 
                             */ 
                            KnowledgeBase kbase = readKnowledgeBase("SampleHumanTaskFormVariables.bpmn"); 
                            //EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" ); 
                             
                             
                             
                            EntityManagerFactory emf  = (EntityManagerFactory) HumanTaskStartupServlet.context.getBean("entityManagerFactoryJbpmPersistanceJpa"); 
                             
                         
                             
                            Environment env = KnowledgeBaseFactory.newEnvironment(); 
                            env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf ); 
                            env.set( EnvironmentName.TRANSACTION_MANAGER, HumanTaskStartupServlet.context.getBean("bitronixTransactionManager") ); 
                            env.set( EnvironmentName.TRANSACTION, HumanTaskStartupServlet.context.getBean("bitronixTransactionManager") ); 
                            env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
                             
                            Properties properties = new Properties(); 
                            properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory"); 
                            properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory"); 
                            KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
                         
                            return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);
                                 
                        } 
                        

                     

                    Thanks!

                    • 7. Re: JBPM5, Spring, BTM and Tomcat
                      jbpmdev

                      Thanks for the quik reply.

                       

                      Actually i confused with the below two steps,

                       

                      env.set( EnvironmentName.TRANSACTION_MANAGER, HumanTaskStartupServlet.context.getBean("bitronixTransactionManager") );
                      env.set( EnvironmentName.TRANSACTION, HumanTaskStartupServlet.context.getBean("bitronixTransactionManager") );

                       

                      Now i have corrected and it is working fine now HSQL db

                       

                      Also for all the transaction, i am using the same "bitronixTransactionManager" object like below,

                       

                      bitronixTransactionManager.begin();

                      bitronixTransactionManager.commit()

                       

                      is that correct ??

                       

                       

                      Still i found the "StatefulKnowledgeSession" and all BPMN conf  also configurable in spring itself instead of doing this way,i have to implement like this later.

                      http://community.jboss.org/message/599448

                       

                       

                      Now i am trying to use XA Database to point Oracle.getting some issues

                       

                      Thanks again for your help!!

                       

                      Tc.
                             

                      • 8. Re: JBPM5, Spring, BTM and Tomcat
                        sasir

                        Guys,

                        Are you also using JPA in your project. Am trying to use Spring 3 + JTA + JPA + Bitronix. I dont have any issues in persisting data into Task/Process tables howevfer whiel inserting into APP DB, no data is getting inserted and no error is shown.

                         

                         

                        In your case, are inserts into app db also part of transaction? if so, Can you please share that configuration

                        • 9. Re: JBPM5, Spring, BTM and Tomcat
                          gigazhang

                          Thanks for your tipic!