A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Elasticsearch in Action
this week in the
Object Relational Mapping
jpql MAX function help needed
Joined: Jun 17, 2012
Nov 26, 2012 21:47:41
EntityManager em = ... Query q = em.createQuery ("SELECT MAX(x.price) FROM Magazine x WHERE x.title = 'JDJ'"); Number result = (Number) q.getSingleResult ();
the query above returns an int which is the price of the magazine.
what i need is to get the whole Entity Magazine.
I'm using Glassfish Server v3.1,
EE 6 and persistence provider eclipselink
Joined: Mar 07, 2010
Nov 27, 2012 06:35:36
You could use a subquery
EntityManager em = ... Query q = em.createQuery ("SELECT m FROM Magazine m WHERE m.price = (SELECT MAX(x.price) FROM Magazine x WHERE m = x AND x.title = 'JDJ')"); Magazine result = (Magazine) q.getSingleResult ();
How To Ask Questions
Read before you PM me
It is sorta covered in the
JavaRanch Style Guide
subject: jpql MAX function help needed
JPA native Query - Select... where... IN, How to set list of values to setParameter()?
WA #1.....word association
I can set the max results on a query, but can I find what the total would have been without (Paging)
JPA - getSingleResult Error
dynamically create attendance sheet in jsp
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015