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

Moderator: admin

Post Reply
johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

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

Post by johnlong » Fri Dec 23, 2016 2:54 pm

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)

admin
Site Admin
Posts: 8239
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Fri Dec 23, 2016 10:28 pm

That is a good question but unfortunately, the specification doesn't give any reason why.
-Paul.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

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

Post by johnlong » Sat Dec 24, 2016 11:31 am

Does specification say that we can't use identification variable in SIZE?

admin
Site Admin
Posts: 8239
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Sun Dec 25, 2016 1:09 pm

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.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

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

Post by johnlong » Sun Dec 25, 2016 6:24 pm

Thank you

henri.davids
Posts: 7
Joined: Tue Sep 04, 2018 9:51 am
Contact:

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

Post by henri.davids » Sun Sep 16, 2018 6:31 am

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?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests