• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

My exam cloud mock exam 1 , SELECT NEW Integer  RSS feed

 
Ranch Hand
Posts: 1732
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
Himai Minh
Ranch Hand
Posts: 1732
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried this SELECT NEW java.lang.Long(MAX(e.salary)) FROM EMPLOYEE e.
It works.
 
Creator of Enthuware JWS+ V6
Posts: 3272
296
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are correct "C" is wrong.

From the JPA specs:

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.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!