如何在 Hibernate 中设置内部查询限制?
我有这样的 HQL:
from Table1 t1 where t1.name not in (select t2.name from Table2 t2 order by t2.date limit 10)
问题是它不理解 limit
关键字。有没有办法运行这样的查询而不将其分成两个子查询?
I have HQL like this:
from Table1 t1 where t1.name not in (select t2.name from Table2 t2 order by t2.date limit 10)
The problem is it doesn't understand limit
keyword. Is there a way to run such query without splitting it into two subqueries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看 如何在 HQL 中进行限制查询?
你不能用 hql 来限制用 hql 编写的查询。您需要在 Query 对象上调用 setMaxResults,我想这会阻止您对 hql 子查询应用限制。
这让您可以选择将
look at How do you do a limit query in HQL?
you can't limit a query written in hql with hql. You need to make a call to setMaxResults on the Query object, which i guess will prevent you from applying a limit on a hql subquery.
This leave you with the option of
如果您将查询作为 SQLQuery 提交,然后将类添加为实体,则可以使用 limit,因为查询是作为 sql 提交的。不过,您必须使用 sql 语法。
--> (也可以使用子选择)
If you submit the query as an SQLQuery and then add your class as an entity, you can use limit, as the query is submittet as sql. You have to use sql Syntax though.
--> (also working with subselects)