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 吧

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料