Which Java Persistence query uses the aggregate function correctly?
A. SELECT ANY(g.cost) FROM Gift g
B. SELECT NEW Integer(MAX(g.cost)) FROM Gift g
C. SELECT g FROM Gift g where g.cost>AVG (g.cost)
Correct answer is B
Regarding to this, I tried something similar, SELECT NEW Long (MAX(e.salary)) From Employee e, it throws a null pointer exception.
I guess it just happen to Eclipselink.
Also, one more note I want to add to the explanation is :
C is not correct aggregate function can only be use in SELECT, HAVING, Order by and Group by clauses, not in WHERE clauses.
posted 3 years ago
I just tried this SELECT NEW java.lang.Long(MAX(e.salary)) FROM EMPLOYEE e.
4.8.2 Constructor Expressions in the SELECT Clause A constructor may be used in the SELECT list to return an instance of a Java class. The specified class is not required to be an entity or to be mapped to the database. The constructor name must be fully qualified.
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!