JPQL限制查询 [英] JPQL limit query
本文介绍了JPQL限制查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何限制JPQL命名查询的选择查询?我需要在查询级别本身而不是在Java层中完成限制!!! 我正在尝试使用
How can I limit in a select query of JPQL named query? I need the limit to be done in the query level itself and not in the java layer!!! I am trying to use
@NamedQueries(value = {
@NamedQuery(name = UserNotification.QueryName.NOTIFICATION_DISPLAYED,
query = "SELECT un FROM UserNotification un " +
"WHERE un.orgId IN (:orgList) " +
"AND un.user.id = :userId LIMIT 5")
但徒劳!!!
请建议
推荐答案
JPQL
不提供限制查询的机制.这通常是通过在Query
上使用setMaxResults()
方法来实现的.如果必须避免在Java代码中进行指定,则可以在包含查询并执行限制的数据库中进行查看.然后将实体映射到此视图,就像创建表一样.
JPQL
does not provide a mechanism to limit queries. This is most often achieved by using the setMaxResults()
method on the Query
. If you must avoid specifying this in Java code, you could make a view in the database that contains your query and performs the limit. Then map an entity to this view as you would a table.
示例:
List<String> resultList= query.setMaxResults(100).getResultList();
这篇关于JPQL限制查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文