意外标记 :( 子查询 hql

unexpected token : ( subquery hql

这是我的 HQL 查询

FROM com.mysite.ActeurInterne act WHERE act.acteurId IN
(SELECT DISTINCT COALESCE(acteurInterne.acteurInternePrincipalId, acteurInterne.acteurId)
FROM
  (SELECT DISTINCT acteurInterne
  FROM com.mysite.ActeurInterne AS acteurInterne
  JOIN acteurInterne.roleSet.roles                                     AS role
  WHERE acteurInterne.acteurId = acteurInterne.acteurId
  AND acteurInterne.nom LIKE :likenom
  AND (role.dateFermeture IS NULL
  OR role.dateFermeture   >= TRUNC(SYSDATE))
  AND (role.dateOuverture IS NULL
  OR role.dateOuverture   <= TRUNC(SYSDATE))
  AND (role.type           = :type
  OR role.type             = :typeC)
  )
)

我明白了

 org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 190 

也就是上面第四行开头的“(”

( SELECT DISTINCT acteurInterne

Hibernate 文档指出子查询只允许在 SELECT 或 WHERE 子句中使用。

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

但在上面的示例中,您在第一个子查询的 FROM 子句中有一个子查询。

您是否尝试过将 2 个子查询合并为一个?

FROM com.mysite.ActeurInterne act WHERE act.acteurId IN
(SELECT DISTINCT COALESCE(acteurInterne.acteurInternePrincipalId, acteurInterne.acteurId)
  FROM com.mysite.ActeurInterne AS acteurInterne
  JOIN acteurInterne.roleSet.roles                                     AS role
  WHERE acteurInterne.acteurId = acteurInterne.acteurId
  AND acteurInterne.nom LIKE :likenom
  AND (role.dateFermeture IS NULL
  OR role.dateFermeture   >= TRUNC(SYSDATE))
  AND (role.dateOuverture IS NULL
  OR role.dateOuverture   <= TRUNC(SYSDATE))
  AND (role.type           = :type
  OR role.type             = :typeC)
)