my dog learned polymorphism*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes EJB-QL question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "EJB-QL question" Watch "EJB-QL question" New topic
Author

EJB-QL question

jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
Page 434 HF EJB.
Can someone explain to me why answer B is correct?Which part of the query ensures that the orders returned have line items?Does the IN(o.lineItems) li
just mean "let li represent an individual line item in the Order Collection?
jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
You can ignore my previous question.Mastering seems to explain this clearly.
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
Jeff,
Can you please post what Mastering says regarding this. I too had this doubt and would like to understand how this works.
jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
On page 573,Roman says

the variables. For example:
SELECT OBJECT(o)
FROM Order AS o, Customer AS c
The above query finds all orders if and only if there are any customers (which
do not need to be related to the Order objects). Even though we aren't using the
variable c anywhere else, we are still excluding orders if there are no cus´┐Ż
tomers. By declaring a variable, you are constraining the domain of the query.
This is similar to the following SQL statement that returns all orders so long as
there are one or more records in the Customer table:
SELECT o.*
FROM Order o, Customer c


As the first line states , The above query finds all orders if and only if there are any customers (which do not need to be related to the Order objects)

That explain why

jeff mutonho
jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
Meant , The "if and only if" explains why.

jeff mutonho
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
Thanks for that Jeff, but somehow I feel a little squeamish about this...
jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
Why?What is that you're not understanding?
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
I understand it...just meant to say that this was not very intuitive for me.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by jeff mutonho:
Does the IN(o.lineItems) li just mean "let li represent an individual line item in the Order Collection?


I kind of touched on that issue in HFEJB p.415: Comma in EJB-QL expression by referring to the EJB-QL language defintion.

Originally posted by B Sathish:
somehow I feel a little squeamish about this...


I think that queasy feeling is just a natural reaction to the tension resulting from the uneasy co-existence of the relational and object paradigm within EJB-QL.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5

This is similar to the following SQL Statement all orders so long as there are one or more records in the Customers Table:
SELECT o.*
FROM Order o, Customer c

And in which way is this explanation supposed to be helpful? Thats like saying multiplying any number by zero results in zero. In fact that query is pretty much useless as it produces a cartesian product. To make my point here are some examples from the pointbase database that comes with the Sun RI 1.4 J2EE server:
jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271

This is similar to the following SQL Statement all orders so long as there are one or more records in the Customers Table:
SELECT o.*
FROM Order o, Customer c


The confusion came from how specifying " Customer c " introduces the condition that the results will depend on the existence of "one or more records in the Customers Table"
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by jeff mutonho:
" Customer c " introduces the condition that the results will depend on the existence of "one or more records in the Customers Table"

I'm objecting to the book presenting it as a special case. In SQL it is understood that if you don't specify a join condition the result will be the cartesian product of the (two, three, four,...) tables - which means every row "will be joined" with every other row. So if any one table contains zero rows - the result has no rows - big surprise. :roll:

The passage in the book (in this context) is silent on the fact that

will produce a cartesian product (see EJB Spec 11.3.5 p.238). Example: If there are 3 orders and 5 customers, that query will present each of the three orders to you five times.
Once you understand that it produces a cartesian product the behaviour they are pointing out is no longer "surprising". Instead they make it look like a special case just to avoid having to explain what a cartesian product is.

With

you indicate that you wish to use the defined CMR between customer and order "as join condition", i.e.:

[ November 02, 2005: Message edited by: Peer Reynders ]
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
I am relieved now :

SELECT OBJECT(o) FROM Order AS o, Customer AS c

will give a cartesian product
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB-QL question
 
Similar Threads
Dont collapse JTree after refresh?
Automatic Installation of 100+ Open Source Projects for Java Developers
JDebugTool 4.2.1 - Graphical Java Debugger
regex help
Can someone help me with a regular expression?