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 ??
SCJP | SCWCD | SCBCD | SCWSD 5 | SCEA (I) 1.4 | SCEA 5 | IBM SOA 669
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.
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