This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

My exam cloud mock exam 1 , SELECT NEW Integer

 
Ranch Hand
Posts: 1742
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: 1742
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: 3290
296
Android Eclipse IDE Chrome
  • 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!