2 Replies Latest reply on Oct 16, 2012 5:56 PM by ajcmartins

    Unwanted automatic update of entities..

    ajcmartins

      Hey, i have spent so much time around this that i can no longer even understand if this is the default behavior:

       

      I have a simple entity that i get from a cache as follows:

       

       

      ...

      @Inject

      @PersonsCache

      Cache<String, Person> cache;

       

       

      public Person getPerson(String name){

           return cache.get(name);

      }

      ...

       

      Then at a different part of the program i change the age property to something. Everything works as it should, except if i search the same entity using the same method above, the entity will have the age property changed, despite me not having done any update on the cache like cache.put(....). Using Lucene to make a query also returns the entity updated..

       

      Is this the default behaviour? It doesn't feels right and from what i readed on the docs it shouldn't be.. Any idea why this may be happening or how can i make it to not persist the changes?

       

      Note: Using infinispan-cdi 5.2.0Beta2 and JBoss 7.1.1Final.

       

      Cheers,

        • 1. Re: Unwanted automatic update of entities..
          jacob1111

          Hi,

           

          I think you should look at the response

          https://community.jboss.org/message/728640#728640

           

          " On the local node Infinispan does not copy the inserted objects and keeps a reference to the original object instead (unless you enable storeAsBinary). So all the changes made to those objects are automatically visible in the cache, but that is just an accidental effect of how Infinispan stores values - there isn't any effort to track changes to your objects and update the values in the cache.

           

          The remote nodes obviously can't hold a reference to your objects, so they won't see any changes this way. The old JBossCache project had a "POJO Edition" that would track changes to objects and automaticall update the copies on all the cluster nodes, but it hasn't been ported to Infinispan.

           

          Jacob Nikom

          • 2. Re: Unwanted automatic update of entities..
            ajcmartins

            Thank you so much Jacob, this certainly explains what's going on.

             

            Cheers,