3 Replies Latest reply on Feb 22, 2011 3:50 AM by Bertrand Renuart

    Infinispan & Hibernate Relationship: How do they work with each other?

    Nedland Rome Newbie

      I'm trying to get a better understanding of how Infinispan and Hibernate work with each other and how they make use of each others services. I'm new to both but I have some understanding of how they work individually but a little confused with how they work together.


      Hibernate can use Infinispan as a 2L cache; but how exactly does it do so? Does Hibernate use Infinispan API to cache.put("queries")?


      Can Infinispan use hibernate as a cache loader?


      Will enabling infinispan as a 2L cache in hibernate be sufficient to store some objects in cache memory? Or will I be required to persist an object through hibernate and mysql AND use the cache.put(key, object). Like so:


      Session session = sessionFactory.openSession();
      for (Integer i = 0; i < 10; i++) {
           session = sessionFactory.getCurrentSession();
           car[i] = new Car(null, this.randomName(), this.randomBrand(), this.randomCost());
           // persist in Hibernate
           int tempI = i;
           i = defaultCache.size();
           // add to cache in memory
           defaultCache.put(i.toString(), car[tempI]);
           i = tempI;


      If 2L is sufficient how can I access this object? What does hibernate use as the key?


      Thanks in advance!