Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, your <code>System.out.println()</code> statement will get executed every time whether or not 2nd level cache is accessed because such access takes place within <code>list()</code> method.</p> <p>Secondly, Criteria - much like Query - does <strong>not</strong> automatically use 2nd level cache; configuration properties you've specified merely <strong>enable</strong> it to be used. You still need to explicitly mark each Query / Criteria instance as cacheable by calling <a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/Criteria.html#setCacheable(boolean)" rel="nofollow noreferrer"><code>setCacheable(true)</code></a>:</p> <pre><code>Criteria crit = ...; crit.setCacheable(true); return crit.list(); </code></pre> <p>On a side note, since you're using <code>HibernateTemplate</code> you might as well use it right :-) and get rid of manual <code>doInHibernate</code> wrapper:</p> <pre><code>public List&lt;TestPOJOcategory&gt; getAllCategory(final String keyword, final int nFirst, final int nPageSize, final String sortColumnId, final boolean bSortOrder) { DetachedCriteria crit = DetachedCriteria.forClass(TestPOJOcategory.class); crit.add(Restrictions.ilike("categoryname", keyword)) .addOrder(bSortOrder ? Order.asc(sortColumnId) : Order.desc(sortColumnId)); getHibernateTemplate().setCacheQueries(true); // works on both queries and criteria return (List&lt;TestPOJOcategory&gt;) getHibernateTemplate() .findByCriteria(crit, nFirst, nPageSize); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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