Page 1 of 1
About Question enthuware.oce-jpad.v6.2.492 :
Posted: Mon Jan 02, 2012 3:35 am
by ETS User
I need somebody to confirm that answer D is legitimate.
select count(s.presentations) from Student s
(Assume that presentations is a Collection field in Student)
If s.presentations is collection, you can't put use it as an argument for count operation, you'd have to join first with presentation, like so:
select count (p)
from Student s left join s.presentations p
Re: About Question enthuware.oce-jpad.v6.2.492 :
Posted: Mon Jan 02, 2012 7:30 am
by admin
count(s.presentations) is valid even without a join. You may want to run the sample application verify this. You can get the sample application from:
http://enthuware.com/index.php/mock-exa ... oce-jpa/85
HTH,
Paul.
Re: About Question enthuware.oce-jpad.v6.2.492 :
Posted: Mon Jan 02, 2012 8:08 am
by Guest
I rechecked using your test application and I still don't see how it can work. It fails in the test application also:
Code: Select all
select count(p) from Student s join s.presentations p
returns properly:
Code: Select all
JPA Query Output -
[ArrayList Size=1
[Long : 5]
]
but
Code: Select all
select count(s.presentations) from Student s
does not allow this:
Code: Select all
Exception :org.hibernate.exception.SQLGrammarException: Syntax error: Encountered "." at line 1, column 14.
Re: About Question enthuware.oce-jpad.v6.2.492 :
Posted: Mon Jan 02, 2012 3:30 pm
by admin
May be I am misinterpreting something but as per section 4.8.5:
For all aggregate functions except COUNT, the path expression that is the argument to the aggregate
function must terminate in a state field. 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.
In this case, s.presentation is an association field, so it should work.
But you are right it doesn't work in the test application either.
I am really sorry about the wrong information.
-Paul.
Re: About Question enthuware.oce-jpad.v6.2.492 :
Posted: Fri Jun 01, 2012 4:27 am
by cosminvacaroiu
size would work instead of count
Re: About Question enthuware.oce-jpad.v6.2.492 :
Posted: Mon Aug 13, 2012 5:29 am
by cosminvacaroiu
a association field may be single-valued or collection-valued. So it's single-valued (a single entity).
You can't put max(someEntity).
It doesn't work with collections

The only 2 functions/expressions that work with collection-valued associations are: SIZE & IS EMPTY, which will generate subqueries, which might be confusing, I don't understand why they even put these 2.
Cheers.
Re: About Question enthuware.oce-jpad.v6.2.492 :
Posted: Thu Nov 20, 2014 3:59 am
by javakid
According the discuss above, it seems like the option D is correct.
I have written codes to confirm that count() with collection field is valid.
I thought the correct answer will be 4 options.
Would anyone tell me why option D is not included in the correct answer?
Thanks.
Re: About Question enthuware.oce-jpad.v6.2.492 :
Posted: Sat Feb 28, 2015 2:30 am
by ikotev
Hello I also can confirm written above. Will someone update the question bank and include answer D as correct.
Re: About Question enthuware.oce-jpad.v6.2.492 :
Posted: Sun Mar 01, 2015 6:22 pm
by admin
Updated.
thank you for your feedback!