1

i have 2 table GcmUser and GroupName in many to many relation in hibernate .

my query is :

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

and I got the error: illegal attempt to dereference collection [{synthetic-alias}{non-qualified-property-ref}gcmUsers] with element property reference [userName]

full stack trace:

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)

i can not understand the meaning of the error .and why it comes?????

6
  • 1
    What is gcmUsers.userName?
    – RAS
    Oct 9, 2013 at 11:05
  • private Set<GcmUser> gcmUsers = new HashSet<GcmUser>(0); it's in GroupName and String userName is in GcmUser and i have many to many relationship. Oct 9, 2013 at 11:37
  • IMHO That's why you're getting this exception. You need to first make join on gcmUsers & then use gcmUsers.userName.
    – RAS
    Oct 9, 2013 at 11:55
  • The Hibernate docs state that HQL doesn't need explicit joins - see '14.4 Forms of join syntax - the only difference between Niraj's syntax and the docs appears to be that the docs use (equiv to) GroupName.cmUsers.userName (i.e. name at start), but that doesn't appear to help... Feb 6, 2014 at 16:06
  • 1
    Using the example HQL, both with/without alias, gives errors of either Unable to resolve path [GroupName.gcmUsers], unexpected token [GroupName] or illegal attempt to dereference collection [groupName0_.id.gcmUsers] with element property reference [userName] - for the code I'm dealing with at least (I subbed the column names for consistency). Feb 6, 2014 at 16:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.