-->
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: How best to Cache Criteria Lists using the 2nd level cache
PostPosted: Tue Aug 19, 2008 7:33 pm 
Newbie

Joined: Tue Aug 07, 2007 2:31 am
Posts: 11
I am creating a criteria that returns a list of Order objects the were generated for a specific user on a given day.

The day the order was placed and user an order belongs to is immutable.

I am trying to figure out how to use Hibernate's 2nd level cache to the cache resulting list from calling Criteria.list()

My current search is done as follows however as I understand it, Hibernate will expire the cache if a new order is created for any user on any date. Is this correct? What is a better solution?

Code:
Criteria crit = session.createCriteria(Order.class);
crit.add(Restrictions.eq("user", user));
crit.add(Restrictions.eq("logDate", day));
crit.setCacheable(true);
      
return (List<Order>) crit.list();


If hibernate does not support this I my plan is to cache the list of IDs. If I do this, I will then iterate over the list loading the Order objects by ID. Is this a bad idea? Is there a better way?

Thanks,
Eric


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.