Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-1140

TransientMortalCacheEntry has incorrect implementation of setValue()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 5.0.0.CR4, 5.0.0.FINAL
    • 4.2.1.FINAL, 5.0.0.CR3
    • Core
    • None
    • Hide

      Insert record into table via Hibernate
      Reload record by its ID
      Change non-ID field on the record
      Update the record via Hibernate
      Reload the record by its ID
      Check that the value reloaded matches the updated value

      Show
      Insert record into table via Hibernate Reload record by its ID Change non-ID field on the record Update the record via Hibernate Reload the record by its ID Check that the value reloaded matches the updated value

      The implementation of setValue() in TransientMortalCacheEntry is as follows

         public Object setValue(Object value) {
            return cacheValue.maxIdle;
         }
      

      This leads to problems in the DefaultDataContainer as the following put() code has no effect:

      public void put(Object k, Object v, long lifespan, long maxIdle) {
        InternalCacheEntry e = entries.get(k);
        if (e != null) {
           e.setValue(v);
           InternalCacheEntry original = e;
           e = entryFactory.update(e, lifespan, maxIdle);
           // we have the same instance. So we need to reincarnate.
           if(original == e) {
              e.reincarnate();
           }
        } else {
           // this is a brand-new entry
           e = entryFactory.createNewEntry(k, v, lifespan, maxIdle);
        }
        entries.put(k, e);
      }
      

      The effect of this for me is that when I am not in a JTA enviroment and I take the following steps via Hibernate the result is not cached correctly:

      • Insert record into table via Hibernate
      • Reload record by its ID
      • Change non-ID field on the record
      • Update the record via Hibernate
      • Reload the record by its ID
      • Check that the value reloaded matches the updated value

      The 2nd level cache always returns the first inserted record rather than the updated one. Each Hibernate access is inside its own transaction.

      I fixed this locally by overriding the class in the classpath, replacing the setValue() method with the following implementation:

      public Object setValue(Object value) {
         Object original = cacheValue.value;
         cacheValue.value = value;
         return original;
      }
      

      Which also corresponds to the (misspelled ) Javadoc:

      Sets the value of the entry, returing the previous value

              rh-ee-galder Galder ZamarreƱo
              stevenewson Steve Newson (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: