• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB QL query from a mock exam

 
paresh vernekar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Which of the following EJB QL queries will return an Account with a refid value of "CA5"?
EJB-QL
1.SELECT DISTINCT OBJECT (a) FROM AccountSchema a WHERE a.refid = 'CA5'
2.SELECT DISTINCT OBJECT (c) FROM AccountSchema c WHERE b.refid IN ('CA5','DA5')
3.SELECT DISTINCT OBJECT (d) FROM AccountSchema d WHERE d.refid NOT IN ('CA5','DA5','EA5')
4.SELECT DISTINCT OBJECT (b) FROM AccountSchema b WHERE B.refid LIKE '%A5'

My answer was 1.However, the solution says that the correct answers are 1,4.
I am puzzled as to how 4 can be a correct solution, since the question says that refid value of retrieved Accounts should be "CA5". With 4, the result would be anything that has refid ending with "A5". Can someone please throw some light on this?

Thanks & Regards,
Paresh Vernekar
 
Ugender Rekulampally
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paresh,
See the options 2 and 3: they are not defining their reference objects in "from"
for example option 2 says :SELECT DISTINCT OBJECT (c) FROM AccountSchema c WHERE b.refid IN ('CA5','DA5')

b.refid (b is not defined here) so this is wrong. the same case with option 3 also.

The reason why 1 and 4 are correct:
the syntaxt in these two options is right and you don't get any runtime errors(or compiler) ...you may get 0 (zero) returns for query but this is still valid.


Thanks,
Ugender
 
paresh vernekar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ugender,
I agree with you for 1,2 & 3.The only reason for confusion about 4 is that question specifically says "CA5".Suppose the domain values for refid would have consisted of (BA5,AA5,DA5,CA5) using %A5% would return all of them.I am not sure whether that would be the rigth result.

Regards,
Paresh Vernekar
 
Ugender Rekulampally
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paresh,
Actually there is a problem with Option 4. see the "from AccountSchema b" and in "where" it used 'B' not small 'b' which was not defined So here itself the option 4 is wrong.

And I agree with you on selecting just one 'CA5' instead of a set so ...may be this is not a well designed question..

Thanks,
Ugender
 
paresh vernekar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ugender,
I think there would be no problem with option 4 as mentioned by you.The spec says that the identification variables are case insensitive.Reference Section 11.2.6.2 (p224) .

Regards,
Paresh Vernekar
 
Amieya Prabhaker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 & 4 are correct.
the question is which will return CA5.

1 will, and so will 4 as the where clause matches it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic