HQL确实支持子查询,但是它们只能出现在select或where子句中。您提供的示例最好以HQL的直接陈述形式编写。例如:
select count(*) from table t (where table is the entity name)
如果查询所涉及的语句比复杂
(select * from Table),我建议将该逻辑放入视图中,然后根据该视图创建实体。
对于支持子选择的数据库,Hibernate支持查询中的子查询。子查询必须用括号括起来(通常用SQL聚合函数调用)。甚至允许相关的子查询(在外部查询中引用别名的子查询)。
例
from DomesticCat as catwhere cat.name not in ( select name.nickName from Name as name)



