0 Replies Latest reply on Apr 14, 2010 1:31 PM by Ranendra Das

    jBPM - XA transaction

    Ranendra Das Newbie

      Hello,

       

      I want to do Xa transaction with jBPM and another Datasource of my application. Both cases, I am using only Hibernate, no spring.

       

      I started with UserTransaction, then started normal hibernate operation, here DS for Normal Hibertane is XA and JTA is the transaction mode and I am using Weblogic 10 AS. 

       

      Now my normal Hibernate transaction using JTA is working fine, but jBPM part is not working fine, I can commit both the DS together, but if there is any exception in my Normal DS, jBPM still commits which is WRONG. I stringly believe I made a mistake somewhere in jBPM configuration. Can anyone tell me where am I wrong?

       

      Here is my code base :-

       

      jbpm.cfg.xml

       

       

       

       

       

       

       

       

       

      <

      jbpm-configuration>

       

       

      <!--

      The default configurations can be found in org/jbpm/default.jbpm.cfg.xml

      Those configurations can be overwritten by putting this file called

      jbpm.cfg.xml on the root of the classpath and put in the customized values.

      -->

       

      <jbpm-context>

       

      <service name="persistence">

       

      <factory>

       

      <bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">

       

      <field name="isTransactionEnabled"><false /></field>

       

      <field name="isCurrentSessionEnabled"><true /></field>

       

      <field name="sessionFactoryJndiName">

       

      <string value="java:/myHibSessFactJndiName" />

       

      </field>

       

      <!--<field name="sessionFactoryJndiName">java:/myHibSessFactJndiName</field>-->

       

      </bean>

       

      </factory>

       

      </service>

       

      </jbpm-context>

       

      <string name="resource.hibernate.cfg.xml" value="hibernate.cfg.xml" />

      </jbpm-configuration>

       

       

       

      hibernate.cfg.xml file

       

       

       

      <?

       

       

      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

      >

       

       

       

      <!-- hibernate dialect -->

       

       

      <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property

      >

       

       

      <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property

      >

       

       

      <property name="hibernate.connection.datasource">jdbc/JbpmDataSource</property

      >

       

       

       

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

      >

       

       

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

      >

       

       

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

      >

       

       

      <property name="hibernate.current_session_context_class">jta</property

      >

       

       

       

       

       

       

      @TransactionAttribute(TransactionAttributeType.SUPPORTS)
         public void doXATransWithHiber()
         {
        try{
        tx = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");
        tx.begin();

        HibernateConfig objHbCfg = null;
        objHbCfg = OfferHibernateUtil.getHibernateConfig(OfferServiceConstant.OFFER_DOMAIN);
        Session session1 = null;

        if(objHbCfg !=null){
         session1 = objHbCfg.currentSession(HibernateConfigType.OFFER);
        }

        OfferPo offerPo= new OfferPo();
        Long offerId= new Long(2574);
        Criteria crit = session1.createCriteria(OfferPo.class);
        crit.add(Restrictions.eq("offerId", offerId));
        offerPo = (OfferPo) crit.list().get(0);
        String processId = offerPo.getOfferProcessId();
        offerPo.setOfferId(offerId);
        offerPo.setOfferName("NewTest_XA_13thApril_2-0");
        session1.persist(offerPo);

        jbpmContext = jbpmConfiguration.createJbpmContext();
        SessionFactory sessfac = (SessionFactory)new InitialContext().lookup("java:/myHibSessFactJndiName");
        jbpmContext.setSession(sessfac.getCurrentSession());
        long processInstanceId = 126694;
        ProcessInstance processInstance = jbpmContext.loadProcessInstance(processInstanceId);
        processInstance.signal();
        jbpmContext.save(processInstance);
        tx.commit();
        }catch(Exception e)
        {
         e.printStackTrace();
         try{
          if(tx !=null){
           tx.rollback();
         }
         }catch(Exception sqle)
         {
          sqle.printStackTrace();
         }
        } finally{
         jbpmContext.close();
        }
         }

       

       

       

       

       

      Regards,

      Ranen

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      Regards,

      Ranen

       

       

       

       

       

       

       

       

       

       

       

       

       

      Regards,

      Ranen

       

       

       

       

       

       

       

       

       

       

       

       

      Regards,

      Ranen

       

       

       

       

       

       

       

       

       

       

       

      Regards,

      Ranen

       

       

       

       

       

       

       

       

       

       

      Regards,

      Ranen