(HQL) 如何设置两个限制?
(HQL) How to put two limits?
我知道我们使用 query.setMaxResults() 在 HQL 中设置限制,但是当我在查询中需要两个限制时呢?
例如:
Select t from Table as t where t.id = 1 and t.date > (Select t2.date from Table as t2 where t2.id = 2 order by date desc limit 1) order by date desc limit 1;
如果我输入query.setMaxResults(1),它会应用到外层select,但我应该如何应用到内部select语句?
谢谢
Hibernate 和 JPA 都无法通过其各种 Criteria-based API 及其 HQL/JPQL string-based API 作为标准支持。
但是您仍然可以使用本机 SQL 来执行此操作。
我知道我们使用 query.setMaxResults() 在 HQL 中设置限制,但是当我在查询中需要两个限制时呢?
例如:
Select t from Table as t where t.id = 1 and t.date > (Select t2.date from Table as t2 where t2.id = 2 order by date desc limit 1) order by date desc limit 1;
如果我输入query.setMaxResults(1),它会应用到外层select,但我应该如何应用到内部select语句?
谢谢
Hibernate 和 JPA 都无法通过其各种 Criteria-based API 及其 HQL/JPQL string-based API 作为标准支持。
但是您仍然可以使用本机 SQL 来执行此操作。