• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

HFEJB - question page 428 - # 12.

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic