-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: My Dao fetching a list not not being Cached
PostPosted: Mon Dec 15, 2008 3:11 am 
Newbie

Joined: Mon Dec 15, 2008 1:32 am
Posts: 3
[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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.