Hi,
While practicing today I stumbled upon this enthuware's question:
Given that a Student may enroll in many Courses. Match the following queries with the result returned by the queries. (Assume that relationship is bidirectional).
1. SELECT s from Student s
Ans: get all students
2. SELECT c from Student s, IN(s.courses) c
Ans: get all courses having at least one enrollment
3. SELECT s form Student s where s.courses IS EMPTY
Ans: get all students who are not enrolled in any course
4. SELECT s.courses from Student s
Ans: get all courses having at least one enrollment
I agree with the answers given for the first three statements. However, I think that the 4th is not a valid JPQL statement.
According to the JPA specification, section 4.8 (SELECT clause):
Note that the SELECT clause must be specified to return only single-valued expressions. The query below is therefore invalid:
SELECT o.lineItems from Order AS o
What do other fellow ranchers think about this? Am I mistaken here?
Thank you in advance.
[ September 07, 2008: Message edited by: Sergio Tridente ]