Hibernate DB2 ROW_NUMBER()错误

时间:2011-10-18 03:40:04

标签: java hibernate db2

我在使用DB2的ROW_NUMBER()时遇到Hibernate问题,它说QueryException:undefined alias:ROW_NUMBER。该怎么办?感谢

String strQuery= " SELECT c_.name, c_.id, c_.description, ROW_NUMBER() OVER(ORDER BY     
                   c_.name) AS rownum FROM Category as c_ ";
Query query = getHibernateTemplate().getSessionFactory().
getCurrentSession().createQuery(strQuery);

1 个答案:

答案 0 :(得分:0)

ROW_NUMBER()不是DB2中的有效函数,但它位于SQL Server中。您需要rownumber()功能。将您的查询更改为以下内容,它应该有效:

String strQuery= " SELECT c_.name, c_.id, c_.description, rownumber() OVER(ORDER BY     
               c_.name) AS rownum FROM Category as c_ ";