Note that there are some explanatory texts on larger screens.

plurals
  1. POcannot do 2nd level cache
    primarykey
    data
    text
    <h2>in my applicationcontext.xml</h2> <pre><code>&lt;bean id="annotatedsessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="packagesToScan" value="testonly.package.model" /&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle9Dialect&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.use_sql_comments"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cglib.use_reflection_optimizer"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt; &lt;prop key="hibernate.c3p0.min_size"&gt;5&lt;/prop&gt; &lt;prop key="hibernate.c3p0.max_size"&gt;20&lt;/prop&gt; &lt;prop key="hibernate.c3p0.timeout"&gt;1800&lt;/prop&gt; &lt;prop key="hibernate.c3p0.max_statements"&gt;50&lt;/prop&gt; &lt;prop key="hibernate.cache.provider_class"&gt; org.hibernate.cache.EhCacheProvider &lt;/prop&gt; &lt;prop key="hibernate.cache.use_second_level_cache"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="dataSource"&gt; &lt;ref bean="dataSource" /&gt; &lt;/property&gt; </code></pre> <p></p> <h2>In my Entity</h2> <pre><code>@Entity @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Table(name = "TestPOJOCATEGORY") @NamedQueries({ @NamedQuery(name = "TestPOJOcategory.findAll", query = "SELECT h FROM TestPOJOcategory h"), @NamedQuery(name = "TestPOJOcategory.findById", query = "SELECT h FROM TestPOJOcategory h WHERE h.id = :id"), @NamedQuery(name = "TestPOJOcategory.findByCategoryname", query = "SELECT h FROM TestPOJOcategory h WHERE h.categoryname = :categoryname")}) public class TestPOJOcategory implements Serializable { </code></pre> <h2>In My Dao</h2> <pre><code>public List&lt;TestPOJOcategory&gt; getAllCategory(final String keyword, final int nFirst, final int nPageSize, final String sortColumnId, final boolean bSortOrder) { List&lt;TestPOJOcategory&gt; result = (List&lt;TestPOJOcategory&gt;) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { Criteria crit = session.createCriteria(TestPOJOcategory.class, "TestPOJOcategory") .add(Restrictions.ilike("categoryname", keyword)) .addOrder(bSortOrder ? Order.asc(sortColumnId) : Order.desc(sortColumnId)) .setFirstResult(nFirst).setMaxResults(nPageSize); System.out.println("why still call from DB? suppose to call from cache"); return crit.list(); } }); return result; } </code></pre> <h2>echcache.xml</h2> <pre><code> &lt;cache name="testonly.package.model.TestPOJOcategory" maxElementsInMemory="200" eternal="true" overflowToDisk="false" timeToIdleSeconds="300" timeToLiveSeconds="600" /&gt; </code></pre> <p>Each time I call the dao, it will still call from DB. Why?</p>
    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. 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