here is a sample code from my dao that gets me a set of results between certain dates.
Code:
public List<EventEnt> searchEvents(Date fromDate, Date toDate, String orderProperty, String orderDirection,
Long first, Long max, String query){
Criteria criteria = getSession().createCriteria(EventEnt.class);
//match the category if not null
// if (venueId != null)
// criteria.add(Restrictions.eq("venue.id", venueId));
//match the query in either description or name
if (fromDate == null) {
GregorianCalendar g = new GregorianCalendar();
g.set(Calendar.YEAR, (g.get(Calendar.YEAR) - 1));
fromDate = g.getTime();
System.err.println(Util.printDate(fromDate));
}
if (toDate == null) {
GregorianCalendar g = new GregorianCalendar();
g.set(Calendar.YEAR, (g.get(Calendar.YEAR) + 1));
toDate = g.getTime();
System.err.println(Util.printDate(toDate));
}
criteria.add(Restrictions.or(Restrictions.ilike("description", query, MatchMode.ANYWHERE),
Restrictions.ilike("name", query, MatchMode.ANYWHERE)))
.add(Restrictions.between("date", fromDate, toDate));
//add the order
if (orderDirection.toLowerCase().equals("asc"))
criteria.addOrder(Order.asc(orderProperty));
else
criteria.addOrder(Order.desc(orderProperty));
//fetch count
criteria.setFirstResult(first.intValue()).setMaxResults(max.intValue());
System.err.println(criteria);
return criteria.list();
}