直接上例子吧
@SuppressWarnings("unchecked")
@Override
public List<AuctionItemEntity> queryActionTopTen() {
try {
Date date=Calendar.getInstance().getTime();
String hql = "from AuctionItemEntity ai where ai.auctionEvent.startTime<=:date and ai.closed=false and ai.rejected=true ORDER BY RAND()";
Query query = getHibernateTemplate().getSessionFactory()
.openSession().createQuery(hql);
query.setTimestamp("date", date);
query.setFirstResult(0);
query.setMaxResults(10);
List<AuctionItemEntity> lst = (List<AuctionItemEntity>) query
.list();
return lst;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}