1

我在休眠中的多对多关系中有 2 个表 GcmUser 和 GroupName 。

我的查询是:

from GcmUser
where clientName='admin'
and  id IN
(
    SELECT id
    FROM GroupName
    WHERE id =
        (
            SELECT id
            FROM GroupName
            WHERE groupName = 'Multy'
            AND gcmUsers.userName ='niraj'
        )
)
order by createdDateTime asc

我得到了错误:illegal attempt to dereference collection [{synthetic-alias}{non-qualified-property-ref}gcmUsers] with element property reference [userName]

完整的堆栈跟踪:

org.hibernate.QueryException: illegal attempt to dereference collection [{synthetic-alias}{non-qualified-property-ref}gcmUsers] with element property reference [userName] [select count(*) as totalcount  from com.bonrix.gcm.demo.model.GcmUser where clientName='admin'and  id IN(SELECT id FROM com.bonrix.gcm.demo.model.GroupName WHERE id =(SELECT id FROM com.bonrix.gcm.demo.model.GroupName WHERE groupName = 'Multy' AND gcmUsers.userName ='gadia'))]
    at org.hibernate.hql.internal.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.java:68)
    at org.hibernate.hql.internal.ast.tree.DotNode.checkLhsIsNotCollection(DotNode.java:550)
    at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:246)
    at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:118)
    at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:114)
    at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:881)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1264)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4297)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3769)
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1947)

我无法理解错误的含义。为什么会出现?????

4

0 回答 0