select sum(counts) from(select count(c) as counts from ChooseJudge c where 1=1 union all select count(f) as counts from FillVacancy f where 1=1)
在数据库运行正常,在java中就报错
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 26 [select count(counts) from(select count(c) as counts from com.zjtl.manage.entity.ChooseJudge c where 1=1 union all select count(f) as counts from com.zjtl.manage.entity.FillVacancy f where 1=1)]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:101)
关于hql语句使用聚集函数的问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 安优小青和他的程序生活 2015-01-07 13:38关注
HQL 语句不支持 union 连接
更不知道你的 counts, 它只会把你的 counts 作为对象去寻找,是找不到pojo类的;
所以,你还是使用 native SQL 吧解决 无用评论 打赏 举报