Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid query?

 
sonali rao
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mock exam question:
Why is the following EJB-QL invalid?
SELECT s.courses from Student s
 
Sudhir V
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
pradeep arum
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sudhir V
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right. If the collection is empty then an empty collection will be returned.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic