views:

47

answers:

2

I have two Entities

University   
   courses

Course
   students

i want to access all the students in a university. I tried the following query

select u.courses.students from university u

i got the following exception.

org.hibernate.QueryException: illegal attempt to dereference collection [university0_.id.courses] with element property reference [students] [ select u.courses.students from com.socialsite.persistence.University u  ]
    at org.hibernate.hql.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.java:46)
  .....

can anyone explain what is wrong with this?

+3  A: 

Well, u.courses is a Collection and doesn't have a students property (which is a property of a single Course).

Pascal Thivent
+1  A: 

i figured it out. Thanks pascal

   select distinct s
   from University u
     inner join u.courses as c
       inner join c.students as s
Anantha Kumaran
Yes, that's it.
Pascal Thivent