限制JPQL中的结果数量 [英] Limit number of results in JPQL

查看:140
本文介绍了限制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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆