如何将MySql子查询转换为HQL子查询
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将MySql子查询转换为HQL子查询相关的知识,希望对你有一定的参考价值。
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!
答案
为什么需要创建别名?尝试仅通过:
选择计数(pl.idProduct)作为来自ProductionLine pl组的veces由pl.idProduct计数(pl.idProduct)>:mayor和count(pl.idProduct)<:menor
to create方法
以上是关于如何将MySql子查询转换为HQL子查询的主要内容,如果未能解决你的问题,请参考以下文章
如何将带有子查询的 MySQL select 语句转换为同一张表的更新语句?