Page 1 of 1

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

Posted: Fri Dec 23, 2016 2:54 pm
by johnlong

Code: Select all

select s from Student s where (select size(p) from s.presentations p) = 1
which is marked as incorrect returns the following result from ToyJPA Test Client

Code: Select all

JPA Query Output - 
[ArrayList Size=1
  [Student : Student[id=3, firstName=Jacob]]
]
And I wonder, if we can use SIZE(collection_valued_path_expression), why can't we do
SIZE(identification variable of collection_valued_path_expression)

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

Posted: Fri Dec 23, 2016 10:28 pm
by admin
That is a good question but unfortunately, the specification doesn't give any reason why.
-Paul.

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

Posted: Sat Dec 24, 2016 11:31 am
by johnlong
Does specification say that we can't use identification variable in SIZE?

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

Posted: Sun Dec 25, 2016 1:09 pm
by admin
The definition for size given in section 4.6.17.2.2 clearly says, "SIZE(collection_valued_path_expression)". It doesn't say anything about "identification variable of collection_valued_path_expression". So it can be interpreted as valid or invalid. I would go with invalid.

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

Posted: Sun Dec 25, 2016 6:24 pm
by johnlong
Thank you

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

Posted: Sun Sep 16, 2018 6:31 am
by henri.davids
I understand that size() is better than count() on collection valued path expressions.
But in test 2 question 12, it is treated valid:
select count(s.presentations) from Student s
(Assume that presentations is a Collection field in Student)
This query works on some implementations but not with others. Ideally, as per Section 4.8.5, which says, "The path expression argument to COUNT may terminate in either a state field or a association field, or the argument to COUNT may be an identification variable.", it is a valid query and should work.
And even in question 47 of test 3 it says:
Note: As per Section 4.8.5, the path expression argument to COUNT may terminate in either a state field or a association field, or the argument to COUNT may be an identification variable. Therefore, the COUNT(s.presentations) should be valid.
Update: Ah, I see, count in where clause is not valid.
So if the answers are ambiguous, what should we remember to be sure the answers are treated correct on the exam?
count() valid on both id-variable and collection-path?
size() not valid on id-variable, but only on collection-path?