如何在Hibernate中设置内部查询限制? [英] How to set a limit to inner query in Hibernate?

查看:119
本文介绍了如何在Hibernate中设置内部查询限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的HQL:

  from Table1 t1其中t1.name不在(从Table2 t2中选择t2.name order by t2.date limit 10)

问题是它不理解限制关键字。有没有一种方法可以运行这样的查询,而不会将它分成两个子查询?

/stackoverflow.com/questions/1239723/how-do-you-do-a-limit-query-in-hql\">你如何在HQL中进行限制查询?



你不能限制用hql写成的查询。您需要在Query对象上调用setMaxResults,我想这会阻止您对hql子查询应用限制。



这会让您选择


  • 将它写为sql-query或
  • 试图找到另一种写hql的方法查询,以便您不需要子查询中的限制。


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?

解决方案

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

  • writting it as a sql-query or
  • trying to find another way to write your hql query so that you don't need a limit in a subquery.

这篇关于如何在Hibernate中设置内部查询限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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