JPQL for select from select row_number() over()

和自甴很熟 提交于 2019-12-19 20:05:03

问题


I'm using Db2 on AS/400, and I am trying to execute a JPQL query that will return results from row x to row y.

In SQL this works:

select cur.* from (
  SELECT ROW_NUMBER() OVER() AS ROWNUM FROM tableName d) as cur
WHERE cur.ROWNUM > 0 AND cur.ROWNUM < 10

How can I do this in JQPL? I tried it in many ways but every time I got an exception.

I want to limit my result inside the query, and not by using the setMaxResult, setFirstResult methods.


回答1:


That cannot be done. JPQL operates to entities and entities are mapped to tables in database. Row number in db2 is concept in result set, not in database table.




回答2:


Query q = em.createQuery("select e from SomeEntity e")
            .setFirstResult(0)
            .setMaxResults(10);


来源:https://stackoverflow.com/questions/11206498/jpql-for-select-from-select-row-number-over

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!