HQL does support subqueries, however they can only occur in the select or the where clause. The example you provide would best be wrote as a straight statement in HQL. For example:
select count(*) from table t (where table is the entity name)
If the query involves a more complicated statement than (select * from Table)
, I would recommend putting this logic into a view and then creating an entity based off of this view.
For databases that support subselects, Hibernate supports subqueries
within queries. A subquery must be surrounded by parentheses (often by
an SQL aggregate function call). Even correlated subqueries
(subqueries that refer to an alias in the outer query) are allowed.
Example
from DomesticCat as cat
where cat.name not in (
select name.nickName from Name as name
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…