1 Reply Latest reply on May 28, 2014 4:55 AM by Antlia Antlia

    Wrong Hibernate Query Cache Configuration

    Antlia Antlia Newbie

      Hi,

       

      I'm using JBoss EAP 6.2.0, experimenting some troubles using Infinispan as Second Level Cache for Hibernate.

       

      I followed the configurations suggested on JBoss forum, setting these values on persistence.xml of my JEEpplication:

       

      standalone.xml

      <cache-container name="hibernate" default-cache="local-query" jndi-name="java:jboss/infinispan/hibernate" start="EAGER" module="org.jboss.as.jpa.hibernate:4">  
             <transport lock-timeout="60000"/>  
             <local-cache name="local-query">  
                  <transaction mode="NONE"/>  
                  <eviction strategy="LRU" max-entries="10000"/>  
                  <expiration max-idle="100000"/>  
             </local-cache>  
             <invalidation-cache name="entity" mode="SYNC">  
                  <transaction mode="NON_XA"/>  
                  <eviction strategy="LRU" max-entries="10000"/>  
                  <expiration max-idle="100000"/>  
             </invalidation-cache>  
             <replicated-cache name="timestamps" mode="ASYNC">  
                  <transaction mode="NONE"/>  
                  <eviction strategy="NONE"/>  
             </replicated-cache>  
      </cache-container>
      
      

      persistence.xml

      <shared-cache-mode>ALL</shared-cache-mode>  
      <validation-mode>NONE</validation-mode>  
      <properties>  
               <!-- Properties for Hibernate -->  
              <property name="hibernate.show_sql" value="true" />  
              <property name="hibernate.format_sql" value="false" />  
              <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />  
              <property name="jboss.entity.manager.jndi.name" value="java:/ReappManager"/>  
              <property name="jboss.entity.manager.factory.jndi.name" value="java:/ReappManagerFactory"/>  
              <property name="hibernate.check_nullability" value="false" />  
              <property name="hibernate.cache.use_second_level_cache" value="true" />  
              <property name="hibernate.cache.use_query_cache" value="true" />  
              <property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/hibernate"/>  
              <property name="hibernate.generate_statistics" value="true" />  
              <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"/>  
            </properties>  
      
      

      And setting

      Query q = entityManager.createQuery(queryString).setHint("org.hibernate.cacheable",true).setHint("org.hibernate.cachemode", "NORMAL")
      
      

      when doing the query.

       

      I'm expecting the query executed only once, the first time, but this is not happening.

      I'm testing it from a REST service and, every time I invoke it, the same SQL is shown on JBoss console, meaning that this query is not actually cached.

       

      I've also enabled TRACE log of Infinispan subsystem (org.infinispan), and it seems all the objects are correctly retrieved and wrapped.

       

      Can anyone help me understanding why Hibernate is always hitting the DB, even if Infinispan retrieves objects from cache?

       

      Thanks,

       

      Antlia