unexpected token : ( subquery hql

落花浮王杯 提交于 2019-12-13 02:27:20

问题


Here's my HQL query

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)
  )
)

I get

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

which is the "(" at the begining of the fourth line above.

( SELECT DISTINCT acteurInterne


回答1:


Hibernate documentation states that sub-queries are allowed only in the SELECT or WHERE clause.

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

But in the example above you have a subquery in the FROM clause of the first subquery.

Have you tried consolidating the 2 sub-queries into one?

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)
)


来源:https://stackoverflow.com/questions/30857140/unexpected-token-subquery-hql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!