为分页设置 maxResults 并按日期设置顺序,但排序仅针对项目的数量(值 maxResults),而不是完整列表。
@Override
public List<News> getNewsList(final List<Integer> rssIds, final int numberOfNewsPerPage, final int indexOfFirstNews) {
HibernateCallback<List<News>> callback = new HibernateCallback<List<News>>() {
@Override
public List<News> doInHibernate(Session sn) throws HibernateException, SQLException {
Query query = sn.createQuery(" from News as n "
+ "where n.rssId in (:idsParam) "
+ "order by :orderby");
query.setParameterList("idsParam", rssIds);
query.setParameter("orderby", "date desc");
query.setFirstResult(indexOfFirstNews);
query.setMaxResults(numberOfNewsPerPage);
return query.list();
}
};