关于HQL查询报错问题
public List<Message> getMessageList(int showCount,int currentPage){
String hql="select title,employeeId,publishTime from (select a.title,a.employeeId,a.publishTime, rownum rn from (select title,employeeId,publishTime from Message)a where rownum<=?)b where rn>?";
List<Message> list =this.
getHibernateTemplate().find(hql,new Object[]{showCount*currentPage,(currentPage-1)*showCount});
return list;
}
关于这个分页HQL语句查询问题,总是报错:unexpected token: ( near line 1, column 42 [select title,employeeId,publishTime from (select a.title,a.employeeId,a.publishTime, rownum rn from (select title,employeeId,publishTime from Message)a where rownum<=?)b where rn>?]
unexpected token: ( near line 1, column 42 [select title,employeeId,publishTime from (select a.title,a.employeeId,a.publishTime, rownum rn from (select title,employeeId,publishTime from Message)a where rownum<=?)b where rn>?]; nested exception is
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 42 [select title,employeeId,publishTime from (select a.title,a.employeeId,a.publishTime, rownum rn from (select title,employeeId,publishTime from Message)a where rownum<=?)b where rn>?]
求朋友们帮忙啊,坐等!!!谢啦
------解决方案--------------------何必这么写呢?hibernateTemplate对分页查询做了很好的封装啊。
private List<Book_view> paging(final int pageSize,
final int pageNow, final String hql) {
return hibernateTemplate.executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
query.setFirstResult((pageNow - 1) * pageSize);
query.setMaxResults(pageSize);
List list = query.list();
return list;
}
});
}
用setFirstRes