Win a copy of 97 Things Every Java Programmer Should Know 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

My exam cloud mock exam 1 , SELECT NEW Integer

 
Ranch Foreman
Posts: 1897
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 Foreman
Posts: 1897
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: 3341
303
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.

 
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!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic