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

jas*_*son 11 grails hibernate hql grails-controller

我正在尝试使用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'
Run Code Online (Sandbox Code Playgroud)

问题是,当我尝试在这样的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'" )
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

  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']
Run Code Online (Sandbox Code Playgroud)

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

谢谢杰森

And*_*ich 37

HQL不支持联合.Hibernate的JIRA中存在一个问题,该问题自2005年开始.