0 Replies Latest reply on Aug 20, 2013 12:15 PM by ajanz

    using JTA Transactions in jBPM 3

    ajanz

      Hello,

       

      we are still using jBPM 3.2.3. ( seam and richfaces for frontend )

       

      Due to some data inconsistencies between jBPM and our data, i wanted to use JTA Transactions to get control over commit and rollback.

       

      although i read the documentation i am not quite sure how to use it the right way.

       

      in jbpm.cfg.cml  isTransactionEnabled must still set to false, is that right  ?

       

      in hibernate.cfg.xml i change to JTA

      <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>

        <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

        <property name="jta.UserTransaction">java:comp/UserTransaction</property>

       

      Now i want to set the commit and rollback points in our code. i wrote a simple class TransactionManager with three methods "beginTransaction" , "commitTransaction" and "rollbackTransaction".

       

      every method in our code with write access, i extended with these three methods.

       

      beginTransaction does the following

       

      [code]

      // creating new context and store in a ThreadLocal

      jbpmContextThreadLocal.set(cfg.createJbpmContext());

      // on this context start a hibernate transaction

      Transaction  tx = jbpmContextThreadLocal.get().getSession().beginTransaction();

      // and store it also in  a ThreadLocal

              userTransactionThreadLocal.set(tx);

       

      [/code]

       

      commitTransaction

       

      [code]

       

                userTransactionThreadLocal.get().commit();

         userTransactionThreadLocal.remove();

        

          //  explizites flush!

          // s. unter http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.jboss.seam/jboss-//seam/2.0.0.GA/org/jboss/seam/bpm/ManagedJbpmContext.java

         

                        jbpmContextThreadLocal.get().getSession().flush();

          jbpmContextThreadLocal.get().close();

          jbpmContextThreadLocal.remove();

      [/code]

       

       

       

       

      and rollback

      [code]

            userTransactionThreadLocal.get().rollback();

           userTransactionThreadLocal.remove();

          

            jbpmContextThreadLocal.get().close();

           jbpmContextThreadLocal.remove();

      [/code]

       

       

      is this a right way to use JTA Transaction with jBPM ?

       

      or am i doing something wrong?