2 Replies Latest reply on Oct 23, 2013 5:41 AM by chaminda hettigoda

    infinispan cache object update in transaction roll back issue.

    chaminda hettigoda Newbie

      we hope to use infinispan as a in memory data base in the order management system. There we need to do following type of operation. Here cash account cache contain customer cache account loaded from DB.  Say initial balance of the cash account1 is 1000 and cashAccount2 is 2000. we update both cash account in a transaction in a jboss 7.1 application server. what we expect as a result is balances of the both cash account remain without changing since this operation occurred inside the transaction. But unfortunately it even after transaction roll back we can see the update object in side the cache. ut

      what we examine is when we add a object to the cache in side a transaction when the transaction roll back it will remove from the cache. But modification of the existing object remain as it is.


      This is just a sample what we want to do. Actual one involve updating several object in a single transaction.


      Could you please let us know it is possible to use infinispan for this type of opperation.


      cashAccountCache= provider.getCacheContainer().getCache(CACHE_NAME);

              try {


                  CashAccount cashAccount1 = cashAccountCache.get("cashAccNumber1");

                  CashAccount cashAccount2 = cashAccountCache.get("cashAccNumber2");

                  cashAccount1.setBalance( cashAccount1 .getBalance() + 100);

                  cashAccount2.setBalance( cashAccount2 .getBalance() + 200);

                   if(true) throw new RuntimeException();


              } catch (Exception e) {

                  if (utx != null) {

                      try {


                      } catch (Exception e1) {




        • 1. Re: infinispan cache object update in transaction roll back issue.
          Pedro Ruivo Apprentice



          The Infinispa stores the references to the values so you are modifying directly the object (like a Map, if you multiple threads get the same key, they will get the same reference to the object).


          You have a couple of alternatives to mitigate this problem:


          * when you get the account from Infinispan, you can make a defensive copy before modifying it. After doing your changes, you have to put it back in the cache.

          * another alternative, you can use some Object to Grid Mapper that does something similar as above automatically (I'm not 100% sure). take a look at Hibernate OGM - JBoss Community

          * finally, you have an option in Infinispan to store the values as byte arrays. this makes each transaction to have a reference to a copy of the account. in the end, you have to put the account back to the cache. take a look at http://infinispan.org/docs/6.0.x/user_guide/user_guide.html#_store_as_binary


          I hope I was clear.




          1 of 1 people found this helpful
          • 2. Re: infinispan cache object update in transaction roll back issue.
            chaminda hettigoda Newbie

            Hi Pedro


            yes you are correct. When we did the changes to object reference those will not get rollback. what we can do it getting the object from the cache and them clone it before doing any change to it. After that replace the object in the cache from the changed copy.

            Then when the transaction roll back cache roll back the newly add object and kept the original object at cache level.


            Again thanks for your reply. We were at wrong understanding on how transaction work at infinispan.