我是靠谱客的博主 独特热狗,这篇文章主要介绍HQL子查询报错:org.hibernate.hql.ast.QuerySyntaxException: unexpected token...,现在分享给大家,希望可以做个参考。

HQL语句:

select count(*) from (select stu.classId  from Student stu group by stu.classId) t_tmp_count

执行该HQL语句一直报错:org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column 22 [select count(*) from (...  

反复检查该HQL语句,没发现问题;执行对应的sql语句,能正确得到结果;直接上网搜这个异常,也没得到多少有用的信息。


最后不得已,只好用Native SQL查询解决问题。  

解决完后马上又想到可以用下面HQL语句解决问题  

select count(distinct stu.classId)  from Student  

只怪自己当时钻牛角尖。


下班后,专门打开《hibernate_reference.pdf》《第14章 HQL: Hibernate查询语言》。猛然瞥见《14.13. 子查询》小节倒数第二段:

Note that HQL subqueries can occur only in the select or where clauses

原来“HQL子查询只能出现在selectwhere字句中“ 


最后

以上就是独特热狗最近收集整理的关于HQL子查询报错:org.hibernate.hql.ast.QuerySyntaxException: unexpected token...的全部内容,更多相关HQL子查询报错:org.hibernate.hql.ast.QuerySyntaxException:内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部