Page 1 of 1

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

Posted: Sat Mar 14, 2015 10:37 am
by ikotev
Hello,

Second answer:
select s from Student s where (select size(p) from s.presentations p) = 1
is wrong but given explanation is not correct:
size can be used only in where part. But here it is being used in select part. count can be used in the select part.
according to specification:
4.6.17.2 String, Arithmetic, and Datetime Functional Expressions
The Java Persistence query language includes the built-in functions described in subsections 4.6.17.2.1,
4.6.17.2.2, 4.6.17.2.3, which may be used in the SELECT, WHERE or HAVING clause of a query.
I think that problem is when you use SIZE in SELECT clause of sub-queries. This is correct:

SELECT SIZE(s.presentations) FROM Student s

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

Posted: Sat Mar 14, 2015 11:11 am
by admin
You are right, I am not sure why the explanation says that. I checked the specification but couldn't find where it says it can't be used in sub-query.

What I do see that it the definition for size given in section 4.6.17.2.2 says, "SIZE(collection_valued_path_expression)". So something like select size(s.presentations) from Students s would be valid but select size(p) from s.presentations p is not valid.

-Paul.

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

Posted: Sun Mar 15, 2015 11:09 am
by ikotev
Yes Paul correct. As you said it should be collection_valued_path_expression no matter if it is in sub-query or not. Thanks.

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

Posted: Sun Mar 15, 2015 9:06 pm
by admin
Updated the explanation.
thank you for your feedback!