• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Invalid query?

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mock exam question:
Why is the following EJB-QL invalid?
SELECT s.courses from Student s
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic