0 Replies Latest reply on Sep 27, 2012 12:33 AM by Prashanth Kudipudi

    Need help in understanding how Hibernate Query Cache will work.

    Prashanth Kudipudi Newbie



      I am using Infinispan as a Hibernate second level cache.


      I am using Jboss as6, Where 2 node are created i.e node1 and node2 which will forms a cache cluster.


      Here is my doubt: The Query which got successfully executed on the node1 and returned the result to the calling function, happenes to run on the node2 whether it will fetch the data from the cache or from the database?


      In my case when the same query which got successfully executed on the node1, happenes to executed on node2 data is coming from the database. But when it got executed on the node1 for the second time data is coming from cache. So can I say my Query_cache configuration is correct?

      Below is my configuration which I was using for the project:


      framework Versions used for the project: Spring 3.0, Hibernate 3.6, infinispan 4.2 and Jboss as6 as application sever.


      1) In the infinispan-config.xml, I have set the value of maxIdle attribute of <expiration> tag to "-1". 


      2) In the applicationContext.xml, Session Factory is configured as shown below.


      <bean id="sessionFactory" 
             <property name="hibernateProperties">
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.format_sql">true</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>


                    <prop key="hibernate.cache.use_second_level_cache">true</prop>
                    <prop key="hibernate.cache.use_query_cache">true</prop>
                    <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.JndiInfinispanRegionFactory</prop>
                    <prop key="hibernate.cache.infinispan.cachemanager">java:CacheManager/entity</prop>
                     <prop key="hibernate.cache.infinispan.query.cfg">replicated-query</prop>
                    <prop key="hibernate.cache.infinispan.entity.cfg">replicated-entity</prop>
                    <prop key="hibernate.cache.infinispan.collection.cfg">replicated-entity</prop>



      3) I was using criteria API for Queries and set the cacheable property to true.


      Thanks in advance,
      Prashanth K