Since a student can enroll in many courses so Student has probably a CMR collection relation with courses. Pg 233 of Spec says that the "SELECT clause must be specified to return a single-valued expression" So the above query is wrong. The correct query will be select Object(c) from students s, IN(s.courses)c

hey Sudhir I have a question for you on this query? don't you need to see the deployment descriptor for the bean , to know whether Student bean is in CMR or not...and if the bean is not in CMR ,there should not be any error right? >because sonali said there was an error you tried to write a proper query with CMR right? please help

SCJP1.4,SCBCD
Failure is not when you fall down; its only when you fail to get up again.

Sudhir V
Ranch Hand

Joined: Dec 25, 2002
Posts: 143

posted Feb 28, 2004 16:28:00

0

Ya pradeep you are right. I made the best guess and moreever I had encountered this question somewhere during my preparation. [ February 28, 2004: Message edited by: Sudhir Vallam ]

Hi Sudhir I had a question about the correct query posted by u . select Object(c) from students s, IN(s.courses)c In the above , which course object would be returned as a result of the query ?? With a Where clause to the above query it would make sense to return a specific course object but without a Where clause will the above return the entire courses collection ??? - Keith

Sudhir V
Ranch Hand

Joined: Dec 25, 2002
Posts: 143

posted Feb 29, 2004 20:33:00

0

The query will return a collection of all courses for which atleast one student has enrolled. You can use "distinct" to get a set of courses for which atleast one student has enrolled.

Keith Shacks
Greenhorn

Joined: Feb 29, 2004
Posts: 10

posted Mar 01, 2004 08:51:00

0

Sudhir In the above scenario lets say student s1 has enrolled in courses c1,c2 student s2 has enrolled in courses c1 student s3 has not enrolled at all so without DISTINCT will it return c1,c2 and c1 and with DISTINCT clause will it return just c1 and c2 ?? Does it also mean that if the collection is empty it will automatically be not included in the results ? - Keith

Sudhir V
Ranch Hand

Joined: Dec 25, 2002
Posts: 143

posted Mar 01, 2004 16:17:00

0

That's right. If the collection is empty then an empty collection will be returned.