[Running Hibernate 3.3.1]
When I fetch a list(Collection like getAll() method) of items from my DB within my DAO, I set the Query setCacheable(true).setCacheMode(CacheMode.GET). My class-cache has been setup in hibernate config xml file. A new select query is executed every time I try getting d list of Items, dis is as observed from the show sql log. But new select doesn’t happen if I repeatedly get individual item. New query aren’t executed as it appears the Items are being fetched from the second-level cache. I fink I have my parameters properly set. Any diffs in setCacheMode as one of d last methods to b called b4 callin list on the Criteria class? i.e does it matter the order in which methods are called on Criteria api? My list is not being cahced.I fink i have my parameters rightly set.
Code:
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<!-- <property name="hibernate.use_sql_comments">true</property> -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<class-cache class="com.pmega.easybuy.domain.Item" usage="read-write" />
<class-cache class="com.pmega.easybuy.domain.Category" usage="read-only" />
<class-cache class="com.pmega.easybuy.domain.ItemPost" usage="read-write"/>
My Dao code looks :
Code:
try {
tx = session.beginTransaction();
itemPosts = session.createCriteria(ItemPost.class).setCacheable(true).setCacheMode(CacheMode.GET)
.setCacheRegion("itemlist")
.createAlias("item", "item", CriteriaSpecification.INNER_JOIN )
.add(Restrictions.gt( "expiryDate", Calendar.getInstance() ))
.addOrder(Order.desc("datePosted")).list();
tx.commit();
// System.out.println("No of posts : "+itemPosts.size());
}
Tanx in advance. Am using Ehcache