Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, using the second level cache doesn't mean that you can find an object in the cache based on any arbitrary HQL (or Criteria) query. The second cache is only used when accessing the object by its key or when navigating an object graph. </p> <p>So, here, you'll need to use <strong>query caching</strong> (yes, there are 3 caches: the first level cache, the second level cache and the query cache). This needs:</p> <pre><code>session.createQuery("query").setCacheable(true); </code></pre> <p>Or, when using <code>Criteria</code>:</p> <pre><code>session.createCriteria(...).add(...).setCacheable(true); </code></pre> <p>And hibernate properties set (which you have):</p> <pre><code>hibernate.cache.use_second_level_cache=true hibernate.cache.use_query_cache=true </code></pre> <p>Actually, I'd warmly suggest to check the following resources if you want to get a better understanding of the various caching mechanism Hibernate uses and of what Hibernate caches exactly (i.e. "dehydrated" entities): </p> <ul> <li><a href="http://www.javalobby.org/java/forums/t48846.html" rel="nofollow noreferrer">Hibernate: Truly Understanding the Second-Level and Query Caches</a> </li> <li><a href="http://www.devx.com/dbzone/Article/29685/0" rel="nofollow noreferrer">Speed Up Your Hibernate Applications with Second-Level Caching</a></li> <li><a href="http://acupof.blogspot.com/2008/01/background-hibernate-comes-with-three.html" rel="nofollow noreferrer">Hibernate Caches</a></li> </ul> <p>The two first articles are a bit old but still apply. The later is more recent. All are good readings IMO.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload