A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Android Security Essentials Live Lessons
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, 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
I agree. Here's the link:
subject: jpql MAX function help needed
dynamically create attendance sheet in jsp
WA #1.....word association
JPA native Query - Select... where... IN, How to set list of values to setParameter()?
JPA - getSingleResult Error
I can set the max results on a query, but can I find what the total would have been without (Paging)
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014