Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB - question page 428 - # 12.

 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
12 - Given CMP beans CustomerBean, OrderBean and LineItemsBean with the following relationships:

CustomerBean (1) <--> OrderBean(0..n)

OrderBean (a) <--> LineItemsBean (0..n)

Which will return all orders that ***HAVE** items?

A - SELECT DISTINCT o FROM Order o, IN (o.lineItems) li --> OK, wrong - imcomplete query.

B - SELECT DISTINCT OBJECT (o) FROM Order o, IN (o.lineItems) li

C - SELECT OBJECT (o) FROM Order o WHERE o.lineItems = 0 --> o.lineItems is a collection and therefore cannot be compared to a int value.

D - SELECT OBJECT (o) FROM Order o WHERE o.lineItems IS NOT EMPTY. --> OK, that's even makes sense.

My question is:

B - The question statement says : "orders that ***HAVE** items" ...
- Why is the option B enough since there is no consistence (WHERE clause, IS NOT EMPTY, something) in order to check if there are valid collection elements ??

Tks!!
 
Awishek sinha
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Felipe (sorry for so late reply )
the IN clause is used to determine whether an item exist in the list so (o.lineItems) is empty nothing would be return from the query the same happens with the ejb -ql
SELECT OBJECT (o) FROM Order o WHERE o.lineItems IS NOT EMPTY.
 
Napu Sun
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spec 238 11.3.5
EJB QL, like SQL, treats the FROM clause as a cartesian product. The FROM clause is similar to that of
SQL in that the declared identification variables affect the results of the query even if they are not used
in the WHERE clause. The Bean Provider should use caution in defining identification variables
because the domain of the query can depend on whether there are any values of the declared type.
For example, the FROM clause below defines a query over all orders that have line items and existing
products. If there are no Product instances in the persistent store, the domain of the query is empty and
no order is selected.
SELECT OBJECT(o)
FROM Order AS o, IN(o.lineItems) l, Product p
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic