3 Replies Latest reply on Jan 4, 2012 10:34 AM by galder.zamarreno

    Unable to run Infinispan cache in JTA

    hkapil123

      Hello All,

      I am new to infinispan and trying to implement Cache updates in a JTA. Somehow  this doesnt seem to be working.This is not working and cache is getting updated even after calling rollback in a user transaction.

      Here are some details

      • Java (vendor and version) - JDK 1.6
      • Infinispan version - Infinispan 5.0.1
      • App server in use (if relevant) - Weblogic 11g

       

      So I create a cache Configuration and set the transactionmanagerLookup appropriately.

      1. com.xweld.services.cache.infinispan.CacheConfiguration is saved with transactionmanagerLookup set with GenericTransactionManagerLookup class ( as we are using Weblogic app server).
      2. We have a wrapper factory which gives us the required TransactionManagerLookup class. We set this class in cache Config instance. And use this instance to initialilze CacheManager later.

       

      ITransactionManagerLookup txnMgrLookup = CacheTransactionManagerLookupFactory

      .getinstance().getTransactionManagerLookup(

      ITransactionManagerLookup.TXN_MGR_GENERIC);

      cacheConfig.setTransactionMangerlookup(txnMgrLookup);


      3.  We start a Global User transaction using JNDI lookup for UserTransaction object.

        tx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");

       

      3)      4. We call all JDBC updates on Hibernate  entities and cache update on CacheManager , created using the earlier saved CacheConfiguartion value.(step 1)

            5.  We explicitly call tx.rollback on user transaction.(no tx.commit is called)

      5)      The Hibernate  updates are reverted correctly but checking the size of cache reveals that cache size has increased and new entry has been added to cache. The updated caches don’t revert after rollback call.

      I would like to know are we supposed to set any other property to make cache updates work in JTA or if we are not using CacheConfiguration  correctly in a JTA.

       

       

      Thanks

      Hkapil

        • 1. Re: Unable to run Infinispan cache in JTA
          galder.zamarreno

          If you're talking about second level cache in Hibernate, you only need to adjust the Hibernate transaction lookup classes. There's no need to do any modification to Infinispan transaction manager lookup class because the second level cache integration code injects the transaction manager set for Hibernate into Infinispan. If you start fiddling with Infinispan transaction manager lookup class, chances are it might not get configured correctly.

           

          Add some TRACE for org.infinispan and org.hibernate.cache.infinispan packages and check what's going on. Alternatively, you can debug through the code in org/hibernate/cache/infinispan/InfinispanRegionFactory to see whether the transaction manager is configured correclty.

          • 2. Re: Unable to run Infinispan cache in JTA
            hkapil123

            Hello Galder,

            Thanks for the reply.

            We are not using Infinispan here as a second level cache . But as a distributed cache . We have cache manager which update the TreeCache directly. So Infinispan is not used as Hibernate second level cache. 

             

            Thanks

            Hkapil

            • 3. Re: Unable to run Infinispan cache in JTA
              galder.zamarreno

              Right, have you tried configuring Infinispan with the generic transaction manager lookup class? i.e. https://github.com/galderz/infinispan/blob/master/core/src/main/java/org/infinispan/transaction/lookup/GenericTransactionManagerLookup.java

               

              That should be able to locate Weblogic's transaction manager which apparently is in "javax.transaction.TransactionManager" JNDI name. Try that and see if it works. I'd assume that Weblogic creates the user transaction out of the same transaction manager, so configuring that transaction manager lookup class should work.

               

              If you enable DEBUG level on org.infinispan package, you should be able to spot whether the weblogic transaction manager was found correctlly.