About Question enthuware.oce-jpad.v6.2.567 :

Moderator: admin

Post Reply

About Question enthuware.oce-jpad.v6.2.567 :

Post by Peter » Mon Mar 26, 2012 4:29 am


I think the query

select s.courses from Student s

is correct, I test the same query on the toyAppForJPA

SELECT co.lineItems FROM CustOrder co

and get the results:

JPA Query Output -
[ArrayList Size=20
[OrderLineItem : salesapp.OrderLineItem[id=1 quantity=2 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=2 quantity=2 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=3 quantity=4 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=4 quantity=3 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=5 quantity=5 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=6 quantity=3 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=7 quantity=4 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=8 quantity=1 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=9 quantity=3 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=10 quantity=5 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=11 quantity=4 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=12 quantity=5 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=13 quantity=1 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=14 quantity=1 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=15 quantity=4 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=16 quantity=1 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=17 quantity=2 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=18 quantity=5 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=19 quantity=2 item = Not Loaded]]
[OrderLineItem : salesapp.OrderLineItem[id=20 quantity=3 item = Not Loaded]]

Can you explain why it is not a valid query?



Re: About Question enthuware.oce-jpad.v6.2.567 :

Post by Peter » Mon Mar 26, 2012 4:36 am

I checked the specification seems it is correct, but please combine the last choice of enthuware.oce-jpad.v6.2.596

SELECT co.customer FROM CustOrder co

why it is correct?

does single-valued expression mean the returned associated entity must be at most one? but s.courses can have more that one?


Re: About Question enthuware.oce-jpad.v6.2.567 :

Post by M_Z » Tue Mar 27, 2012 3:12 pm

Hi Peter,

When in doubt, use JPA 2.0 specification, not EclipseLink.

JPA 2.0 specification is a Bible for 1Z0-898. ;-)

Please, refer Section 4.8 SELECT Clause:
select_clause ::= SELECT [DISTINCT] select_item {, select_item}*
select_item ::= select_expression [ [AS] result_variable]
select_expression ::=
single_valued_path_expression |
scalar_expression |
aggregate_expression |
identification_variable |
OBJECT(identification_variable) |
If you wish to select values from "collection valued path expression" (specification terminology), there are 2 options:

1) JOIN syntax:

Code: Select all

SELECT o FROM Customer c INNER JOIN c.orders o
2) IN syntax:

Code: Select all

SELECT o FROM Customer c, IN(c.orders) o
Best regards,
Mikalai Zaikin


Re: About Question enthuware.oce-jpad.v6.2.567 :

Post by Peter » Wed Mar 28, 2012 1:14 am

OK, got it


Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm

Re: About Question enthuware.oce-jpad.v6.2.567 :

Post by himaiMinh » Mon Aug 14, 2017 2:24 pm

In the explanation , it says "SELECT li from Order o IN (o.lineItems) li".
I think we need a comma, before the IN like this one:
SELECT li from Order o, IN (o.lineItems) li

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest