shushali123 2015-01-04 06:18 采纳率: 0%
浏览 2332

关于hql语句使用聚集函数的问题

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)

  • 写回答

1条回答 默认 最新

  • 关注

    HQL 语句不支持 union 连接
    更不知道你的 counts, 它只会把你的 counts 作为对象去寻找,是找不到pojo类的;
    所以,你还是使用 native SQL 吧

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示