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 - Chapter 7 - Page 428 - Q # 12 - CMP Question

 
Aleena Rehman
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question # 12:
Given CMP beans CustomerBean,OrderBean and LineItemsBean with the following relationships:
CustomerBean (1) <->OrderBean(n)
OrderBean (1) <-> LineItemsBean(n)

The following answers have been marked as correct in Answers section.
Question: Which will return orders that have lineitems?

Choice B - Select Distinct Object(o) FROM Order o, IN(o.lineItems) li
Choice D - Select Distinct Object(o) FROM Order o where o.lineItems is not empty.

I feel that only choice D should be correct, as the question says "Which EJB-QL will return orders THAT HAVE LINE ITEMS?"

In choice B we donot check if the collection referred is empty or not.

Any suggestions would be valuable ?

Regards,
Aleena
 
Aleena Rehman
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any body help me out ?
 
MI Mohammed
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ale,
Hope you don't mind the name. The answers to that question
is B and D. Ok let look at it. The IN operator is used to return collections
when used in the From clause. In the Order bean class, there must be a method that returns a collection of lineItems like

public abstract Collection getLineItems();

So, when you select everything which the Order class represent, you are including the lineItems. But if you now want to restrict the query to a particular lineItem, you can now do that in the where clause.

Hope it helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic