0

ページング用に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();
        }
    };
4

1 に答える 1

0

If your question is: "how to only sort the items returned by the query, instead of sorting the whole list, and then applying the first and max results constraints?", then it's not possible without sorting the result list explicitely, in Java, using a Comparator.

The alternative is to use a native SQL query, but the query will depend on which database you're using.

于 2012-06-03T11:00:21.707 に答える