【发布时间】:2014-03-28 15:01:52
【问题描述】:
我在 Hibernate 中遇到了一种情况,我需要在 SQL EXCEPT 查询中获取 count(*)。下面是查询(模仿我原来的代码):
String query = """
select count(*) as totalCount
from ( select distinct id from Employee
where name like '%Roger%
EXCEPT select distinct id from Manager ) Temporary
"""
现在,当我说:
hibernateSession.createQuery(query);
抛出以下异常:
org.hibernate.hql.ast.QuerySyntaxException:
unexpected token: ( near line 1, column 36
当我发现异常时,我的日志还会显示以下解析错误:
org.hibernate.hql.PARSER line 1:36: unexpected token: (
org.hibernate.hql.PARSER line 14:315: unexpected token: EXCEPT
org.hibernate.hql.PARSER line 15:68: unexpected token: from
我无法避免计数,WHERE 或 EXCEPT。
【问题讨论】:
标签: sql hibernate grails spring-data