-
1. Re: infinispan cache object update in transaction roll back issue.
pruivo Oct 23, 2013 4:34 AM (in response to hettimora1979)1 of 1 people found this helpfulHi,
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.
Regards,
Pedro
-
2. Re: infinispan cache object update in transaction roll back issue.
hettimora1979 Oct 23, 2013 5:41 AM (in response to pruivo)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.