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