2015-06-16 48 views
1

這裏是我的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

回答

1

Hibernate文檔指出s ub-queries只能在SELECT或WHERE子句中使用。

請注意,HQL子查詢只能出現在select或where子句中。

但在上面的示例中,第一個子查詢的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) 
) 
+0

謝謝你的回答。爲了完整起見,您是否可以告訴一個解決方法來實現'FROM [subquery]'? – Nani

+0

令人驚歎。工作順利..謝謝:) – Nani