限制 JPQL 中的结果数 [英] Limit number of results in JPQL
本文介绍了限制 JPQL 中的结果数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何限制从数据库中检索到的结果数量?
How it is possible to limit the number of results retrieved from a database?
select e from Entity e /* I need only 10 results for instance */
推荐答案
您可以尝试这样给出 10 个要显式获取的结果.
You can try like this giving 10 results to be fetched explicitly.
entityManager.createQuery(JPQL_QUERY)
.setParameter(arg0, arg1)
.setMaxResults(10)
.getResultList();
如果后端支持,它会在后端自动创建原生查询以检索特定数量的结果,否则在获取所有结果后进行内存限制.
It will automatically create native query in back-end to retrieve specific number of results, if the backend supports it, and otherwise do the limit in memory after getting all results.
这篇关于限制 JPQL 中的结果数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文