小编典典

如何在HQL中执行Union SQL语句?

hibernate

我正在尝试使用HQL(hibernate查询语言)在两个表之间创建一个并集。此SQL脚本可在我的SQL服务器上正常运行:

SELECT COUNT(DISTINCT linkedin_id) as test, school_name
FROM
(SELECT * FROM alum_education 
 UNION
 SELECT * FROM alum_connection_educations) AS UNIONS where school_name='some string'

问题是,当我尝试像这样在grails中运行它时:

     def countOfEdu = AlumEducation.executeQuery("select count (distinct linkedinId ) as countOfEdu, schoolName as SchoolName from (SELECT * FROM alumEducation UNION SELECT * FROM alumConnectionEducations) AS UNIONS where schoolName='some string'" )

我收到此错误:

  org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 83 [select count(distinct linkedinId )  as countOfEdu, schoolName as SchoolName  from (SELECT * FROM alumEducation UNION SELECT * FROM alumConnectionEducations) AS UNIONS where schoolName='Duquesne University']

如何在grails中运行上述SQL语句?

谢谢杰森


阅读 1496

收藏
2020-06-20

共1个答案

小编典典

HQL不支持联合。自2005年以来,Hibernate的JIRA中存在一个问题

2020-06-20