如何将MySql子查询转换为HQL子查询

问题描述 投票:0回答:1

hello everyone I have this subquery in mysql working like a charm!

select count(a.veces)
from 
(
        select count(id_product) as veces
        from production_line 
        group by id_product
        having count(id_product) > 2 and count(id_product) < 6
)  as a

And im trying to pass it into the HQL syntax in Hibernate but Im getting a syntax error.. Here is my HQL subquery

Query query = getCurrentSession().
createQuery("select count(a.veces) from 
(select count(pl.idProduct) as veces from ProductionLine pl group by
pl.idProduct having count(pl.idProduct) > :mayor and count(pl.idProduct) < :menor) as a");

However im getting this exception

引起:org.hibernate.hql.internal.ast.QuerySyntaxException

someone can help me? Thank you!

mysql hibernate subquery hql
1个回答
0
投票

为什么需要创建别名?尝试仅通过:

选择计数(pl.idProduct)作为来自ProductionLine pl组的veces由pl.idProduct计数(pl.idProduct)>:mayor和count(pl.idProduct)<:menor

to create方法

© www.soinside.com 2019 - 2024. All rights reserved.