3 Replies Latest reply on Dec 2, 2009 3:11 AM by Galder Zamarreño

    Infinispan Cache Entity Lifespan setting causing problems

    Brian K Newbie

      Hi -- I've been experimenting with using the Infinispan cache provider with Hibernate, and I'm seeing some unexpected behavior when I set the entity lifespan setting. This is happening for me in both 4.0.0 CR1 and CR2 builds. This is in a standalone project (no app server), and there is only one node in the cluster for testing.

      The test I'm running does the following:
      1) Open new Hibernate Session
      2) Create an object and fill in all fields.
      3) Close Hibernate Session
      4) Open new Hibernate Session
      5) Load previously created object and change some fields
      6) Close Hibernate session
      7) Open new Hibernate Session
      8) Load the object and check that the newly set field values are still there

      This test works fine with the default Infinispan Cache settings. Then, I started experimenting with changing some eviction settings in my hibernate.cfg.xml. The settings I tried, again with no issues (and based on the instructions at http://www.jboss.org/community/wiki/UsingInfinispanasJPAHibernateSecondLevelCacheProvider) , are below (just for the sake of experimentation):
      * hibernate.cache.infinispan.entity.eviction.strategy = LRU
      * hibernate.cache.infinispan.entity.eviction.wake_up_interval = 30000
      * hibernate.cache.infinispan.entity.eviction.max_entries = 10000
      * hibernate.cache.infinispan.entity.expiration.max_idle = 300000

      Again, no science to these choices of settings -- just experimenting. The settings above work fine with the test above. However, things break when I try to set the entity lifespan, as below:
      * hibernate.cache.infinispan.entity.expiration.lifespan = 600000

      What happens is, in step 8 above, the loaded object has the original value that was set at object creation, and the cache didn't appear to retain or reload the object changed object. I also checked the database, and the new value set in step 5 is stored there (so the changed value was saved). So it looks like somehow when I change the lifespan setting, it's not updating the cache properly.

      As a potentially related question, are there any special requirements for implementing equals/hashCode for the Infinispan cache provider to work correctly? In my own code I am never sharing/accessing any Hibernate objects between sessions, so based on the Hibernate site I didn't override equals and hashCode.

      Please let me know if you have any thoughts. Thanks.