根据我之前的帖子: How to get an index of different category returned by "order by" sql in oracle?
我想使用Hibernate从我的oracle数据库返回此查询的结果。看来Hibernate在其原生查询创建中不支持此功能。有没有办法在Hibernate中做到这一点?
public List<Object[]> testQuery() {
String queryStr = "select Name, Value, dense_rank() over (order by name) - 1 as idx "
+ "from table order by Name;"
Query query = getEntityManager().createNativeQuery(queryStr);
return query.getResultList();
}
我收到如下错误:
Jul 19, 2016 10:14:17 AM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 933, SQLState: 42000
<Jul 19, 2016 10:14:17 AM PDT> <Warning> <org.hibernate.util.JDBCExceptionReporter> <BEA-000000> <SQL Error: 933, SQLState: 42000>
Jul 19, 2016 10:14:17 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-00933: SQL command not properly ended
<Jul 19, 2016 10:14:17 AM PDT> <Error> <org.hibernate.util.JDBCExceptionReporter> <BEA-000000> <ORA-00933: SQL command not properly ended
或者,如果这太复杂而无法实现,是否有其他方法可以在我的初始帖子中解决问题?