Page 1 of 1

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

Posted: Fri Mar 16, 2012 4:41 pm
by ETS User
I believe option A will also return what is asked in question, the difference with B that it may return some duplicated rows, but each row will correctly show name of student and numberof presentations done by this student. Question must be more explicit if no duplicate rows allowed.

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

Posted: Fri Mar 16, 2012 4:58 pm
by admin
You are right. This has been updated.
thank you for your feedback!

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

Posted: Fri Jul 06, 2012 7:24 am
by hfinit
hello,


I want to ask why select count(s.presentations) directly in option b.

Because "it is illegal to select elements directly from a collection-based relationship."




Thanks in advance

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

Posted: Sun Jul 08, 2012 1:04 pm
by hebolive
hfinit wrote:hello,


I want to ask why select count(s.presentations) directly in option b.

Because "it is illegal to select elements directly from a collection-based relationship."




Thanks in advance
I have the same question.

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

Posted: Mon Jul 09, 2012 7:10 pm
by admin
As explained in the explanation given with the question, it should be valid because presentations is an association field in student.
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.
HTH,
Paul.

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

Posted: Sat Aug 25, 2012 11:13 am
by Guest
admin wrote:As explained in the explanation given with the question, it should be valid because presentations is an association field in student.
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.
HTH,
Paul.
This is very wrong ! by association field it means: single-valued association field, not collection-valued association field ! Think of it, how this could be translated to SQL ? The only two methods that would allow such a strange behavior are: SIZE and IS EMPTY which translate in the SQL with subqueries.

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

Posted: Sat Aug 25, 2012 3:43 pm
by admin
Guest wrote:
admin wrote:As explained in the explanation given with the question, it should be valid because presentations is an association field in student.
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.
HTH,
Paul.
This is very wrong ! by association field it means: single-valued association field, not collection-valued association field ! Think of it, how this could be translated to SQL ? The only two methods that would allow such a strange behavior are: SIZE and IS EMPTY which translate in the SQL with subqueries.
This query seems to work fine on Glassfish using Hibernate as well as EclipseLink. I do not have the generated SQL query right now but you may try the sample app and see the query.
If the specification meant single valuated association field, it would have said so. But I will try to do more research on this and find out.

HTH,
Paul.

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

Posted: Sun Oct 07, 2012 8:44 am
by heaven
The BNF in spec states:

Code: Select all

COUNT ([DISTINCT] identification_variable | state_field_path_expression | single_valued_object_path_expression)
Therefore I think collection is not a valid terminator in count() function by spec definition

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

Posted: Sun Oct 07, 2012 11:10 am
by admin
Well, the BNF settles it. The option has now been changed to

Code: Select all

select s.firstname, count(p) from Student s join s.presentations p group by s.firstname
thank you for your feedback!