HQL转换

时间:2013-06-11 14:54:18

标签: java hibernate hql

我是HQL的新手,我正在尝试这样做:

select count(T) from (
    select inscription, max(wrd_step) as max 
    from table aa 
    where rd_context = ? 
    group by inscription
) as T
where T.max = ?

错误是:

Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 21 [select count(T) from( select inscription, max(wrd_step) from table aa where rd_context = ? group by inscription) as T where T.max = ?]

由于

编辑:

HQL中的查询是:

SELECT count(distinct inscription)
FROM Entity
WHERE inscription in (
    select distinct inscription
    from Entity 
    where rd_context = ?
    group by inscription
    having max(wrd_step) = ?
)

1 个答案:

答案 0 :(得分:1)

Hibernate文档声明:

  

请注意,HQL子查询只能出现在select或where子句中。

http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#queryhql-subqueries

但假设table是映射实体(是吗?),你可以这样做(未经测试):

select count(aa)
from table aa 
where rd_context = :param1 
group by inscription
having max(wrd_step) = :param2