我是一名部分 UI 开发人员,现在我需要转入 Hibernate 开发。今天,当我尝试使用 UNION ALL 时,我在 HQL 中遇到了一个问题,这里是 HQL:
SELECT COUNT(DISTINCT users.userId) AS totalSize FROM (SELECT DISTINCT
d1.sponsor.id AS userId FROM Dating d1 WHERE d1.invitee.id = ? UNION ALL
SELECT DISTINCT d2.invitee.id AS userId FROM Dating d2 WHERE d2.sponsor.id = ?)
AS users
它显示如下错误:
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column 55
然后我尝试将此 HQL 转换为原始 SQL:
SELECT COUNT(DISTINCT users.userId) AS totalSize FROM (SELECT DISTINCT
d1.sponsorId AS userId FROM mmy_dating d1 WHERE d1.inviteeId = 6 UNION
ALL SELECT DISTINCT d2.inviteeId AS userId FROM mmy_dating d2 WHERE
d2.sponsorId = 6) AS users;
它通常会显示正确的结果,所以我在想 Hibernate 是否不支持 UNION ALL 语法?
提前致谢。