4 Replies Latest reply on Feb 7, 2014 5:39 AM by Lars Michael Nørregaard

    JPA query cache

    Lars Michael Nørregaard Newbie



      I have tried to add query and entity cache to my queries on JBoss 7.1.1 and EAP 6.1 and EAP 6.2.

      Entity cache works fine by following the guidelines.


      Query cache is another matter. I have tried different scenarios, but the query will not be hit.  Need to get to my other computer at work.


      Added this to persistence.xml

      <persistence-unit name="cache_persistence">







               <property name="hibernate.show_sql" value="false" />

               <property name="hibernate.hbm2ddl.auto" value="none" />

         <property name="hibernate.cache.use_second_level_cache" value="true"/>

         <property name="hibernate.cache.use_query_cache" value="true"/>

         <property name="hibernate.generate_statistics" value="true"/>




      I'm also using the query hints mentioned in this post:

      Re: Query result caching

      Query hints:

      • javax.persistence.cache.retrieveMode : CacheRetrieveMode
        • BYPASS : Ignore the cache, and build the object directly from the database result.
        • USE : Allow the query to use the cache. If the object/data is already in the cache, the cached object/data will be used.
      • javax.persistence.cache.storeMode : CacheStoreMode
        • BYPASS : Do not cache the database results.
        • REFRESH : If the object/data is already in the cache, then refresh/replace it with the database results.
        • USE : Cache the objects/data returned from the query.

      With USE for both

      I'm using default standalone.xml with only added this datasource. Which configuration is missing?