Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
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, Java 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
rocket mass heater
subject: jpql MAX function help needed
I can set the max results on a query, but can I find what the total would have been without (Paging)
WA #1.....word association
JPA native Query - Select... where... IN, How to set list of values to setParameter()?
dynamically create attendance sheet in jsp
JPA - getSingleResult Error
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013