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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ETS User

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

Post 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

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

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

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

Guest

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

Post by Guest »

admin wrote: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.
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.

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

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

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

cosminvacaroiu

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

Post by cosminvacaroiu »

size would work instead of count

cosminvacaroiu

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

Post 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.

javakid
Posts: 1
Joined: Thu Nov 20, 2014 3:55 am
Contact:

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

Post 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.

ikotev
Posts: 17
Joined: Sat Feb 28, 2015 2:26 am
Contact:

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

Post by ikotev »

Hello I also can confirm written above. Will someone update the question bank and include answer D as correct.

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

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

Post by admin »

Updated.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests