0 Replies Latest reply on Feb 7, 2012 9:21 AM by S Jegan

    Spring + JBpm 5.2 + Bitronix - JTA Transaction not rolling back

    S Jegan Newbie

      Hi All,

       

      We are using JBpm 5.2 with Spring 3 and Bitronix as transaction manager. JBpm is integrated inside our application, we use the LocalTaskService to create tasks etc. All JBpm relates tables are co-existing with our application.

       

      And another thing is that, we do not use JPA, but rather Hibernate. So there is one datasource, an Entity Manager for JBpm and a SessionFactory for our application. We have configured JTA using Bitronix and spring. Below is the configuration.

       

      {code:xml}

        <bean id="transactionManager"

          class="com.tarshan.onebill.common.bpm.service.JTATransactionMgr">

          <property name="transactionManager" ref="bitronixTransactionManager" />

          <property name="userTransaction" ref="bitronixTransactionManager" />

        </bean>

       

        <bean id="btmConfig" factory-method="getConfiguration"

          class="bitronix.tm.TransactionManagerServices">

          <property name="serverId" value="spring-btm" />

          <property name="defaultTransactionTimeout" value="300" />

        </bean>

       

        <bean id="bitronixTransactionManager" factory-method="getTransactionManager"

          class="bitronix.tm.TransactionManagerServices" depends-on="btmConfig"

          destroy-method="shutdown">

        </bean>

       

        <bean id="jbpmDataSource" class="com.tarshan.onebill.common.bpm.vendor.jbpm.ObPoolingDataSource"

          init-method="init" destroy-method="close">

          <property name="className" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />

          <property name="uniqueName" value="jdbc/jbpm" />

          <property name="minPoolSize" value="1" />

          <property name="maxPoolSize" value="3" />

          <property name="acquisitionInterval" value="1" />

          <property name="acquisitionTimeout" value="15" />

          <property name="maxIdleTime" value="15" />

          <property name="useTmJoin" value="true" />

          <property name="deferConnectionRelease" value="true" />

          <property name="automaticEnlistingEnabled" value="true" />

          <property name="allowLocalTransactions" value="true" />

          <property name="driverProperties" ref="driverProperties" />

        </bean>

      {code}

       

      Entity Manager configuration:

       

      {code:xml}

        <bean id="entityMF2"

          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" depends-on="btmConfig">

          <property name="dataSource" ref="jbpmDataSource" />

          <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />

          <property name="loadTimeWeaver">

            <bean

              class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />

          </property>

          <property name="persistenceUnitName" value="org.jbpm.persistence.jpa" />

          <property name="jpaVendorAdapter">

            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">

              <property name="showSql" value="true" />

            </bean>

          </property>

          <property name="jpaProperties">

            <props>

              <prop key="hibernate.connection.autocommit">false</prop>

              <prop key="hibernate.max_fetch_depth">3</prop>

              <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.BTMTransactionManagerLookup

              </prop>

              <prop key="hibernate.show_sql">true</prop>

              <prop key="hibernate.current_session_context_class">jta</prop>

            </props>

          </property>

        </bean>

      {code}

       

      Now, we have a service which starts a process and then inserts some records in our application database. If any of the operation fails, JBpm is not rolling back the transaction. The weird thing is that, I could see from the log that Bitronix is rolling back the transaction. I could also see that JBpm is only joining the existing transaction at TaskServiceSession (because we have set transactionType as "local-JTA" while starting the task service).

       

      {quote}

      126224 07/02 18:46:01,358[main] DEBUG bpm.service.JTATransactionMgr.processRollback  - Initiating transaction rollback

      Inside doRollback

      129134 07/02 18:46:04,268[main] DEBUG bitronix.tm.BitronixTransactionManager.debug  - rolling back transaction a Bitronix Transaction with GTRID [737072696E672D62746D0000013557F39D0A00000000], status=ACTIVE, 1 resource(s) enlisted (started Tue Feb 07 18:44:37 IST 2012)

      129135 07/02 18:46:04,269[main] DEBUG tm.timer.TaskScheduler.debug  - cancelling transaction timeout task on a Bitronix Transaction with GTRID [737072696E672D62746D0000013557F39D0A00000000], status=ACTIVE, 1 resource(s) enlisted (started Tue Feb 07 18:44:37 IST 2012)

      129136 07/02 18:46:04,270[main] DEBUG tm.timer.TaskScheduler.debug  - removing task by a Bitronix Transaction with GTRID [737072696E672D62746D0000013557F39D0A00000000], status=ACTIVE, 1 resource(s) enlisted (started Tue Feb 07 18:44:37 IST 2012)

      {quote}

       

      I am really not clear why the records are still persisted in JBpm tables. Please help me fix this issue. Not sure what I am doing wrong. I could be missing something very basic. Have also uploaded the persistence.xml file.

       

      Thanks for your time.

       

      Regards,

       

      Jegan