File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Invalid query? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Invalid query?" Watch "Invalid query?" New topic
Author

Invalid query?

sonali rao
Ranch Hand

Joined: Nov 03, 2003
Posts: 64
Mock exam question:
Why is the following EJB-QL invalid?
SELECT s.courses from Student s
Sudhir V
Ranch Hand

Joined: Dec 25, 2002
Posts: 143
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


Sudhir V<br />(SCJP 1.2, SCWCD, OCA, SCBCD)
pradeep arum
Ranch Hand

Joined: Oct 01, 2003
Posts: 130
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
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 ]
Keith Shacks
Greenhorn

Joined: Feb 29, 2004
Posts: 10
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
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
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
That's right. If the collection is empty then an empty collection will be returned.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid query?