• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFE Page 428 - Q12 : EJB-QL (one to many relationship)

 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
On page 428, Q 12 says-

Given CMP bean customerBean, orderbean, lineitembean with following relationship...
customerbean (1)<--> orderbean(n)
orderbean (1)<--> lineitembean(n)
Which will return all orders that have line items ?

the correct ansers are -
B. SELECT DISTINCT OBJECT(o) FROM order o IN (o.lineitems)li
D. SELECT DISTINCT OBJECT(o) FROM order o
I feel these answers are wrong. The questions says that orders that have line items. so the query should be...
SELECT DISTINCT OBJECT(o) FROM order o where o.lineitems IS NOT EMPTY
Same type of query is written on page 418, where director has many movies and you want to select all directors having movies associated.
Can someone explain the above metioned answers in HFE?
 
Sudhir V
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right. I submitted this error to the errata list and its unconfirmed from Kathy. Check the link at the bottom (they are sorted by Pg numbers see Pg 434)
http://www.oreilly.com/catalog/hfjejb/errata/hfjejb.unconfirmed
 
Jack Zhou
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the correct ansers are -
B. SELECT DISTINCT OBJECT(o) FROM order o IN (o.lineitems)li
D. SELECT DISTINCT OBJECT(o) FROM order o
I feel these answers are wrong. The questions says that orders that have line items. so the query should be...
SELECT DISTINCT OBJECT(o) FROM order o where o.lineitems IS NOT EMPTY

B is equivlent to your ql.
here is quote from spec on page 224.
An identification variable designates an instance of an entity bean abstract schema type or an element of
a collection of entity bean abstract schema types instances. Identification variables are existentially
quantified in an EJB QL query.

I think IN(o.lineItems)l means there exists l in 0.lineIems.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic