File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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,
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
JpA + select nvl(max(att),0)
Doubt in Sun's sample question
Querying in JPA
JPA Facade and DAO
How do criteria API and subqueries work?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015