意外的令牌:(子查询hql [英] unexpected token : ( subquery hql

查看:120
本文介绍了意外的令牌:(子查询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)
  )
)

我得到

I get

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

这是(开头。

)SELECT DISTINCT acteurInterne

( SELECT DISTINCT acteurInterne

推荐答案

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

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


请注意,HQL子查询只能出现在select或
子句中。

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

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

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

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

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

这篇关于意外的令牌:(子查询hql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆