Does hibernate support HQL queries with select min, max, count and other sql functions?
like
select min (p.age) from person p
thanks
Yes, min() , max() and count() supported in HQL.
min()
max()
count()
see aggregate functions in the Hibernate Doc.
thats how i use max in hibernate:
public long getNextId(){ long appId; try{ Session session = HibernateUtil.getAdmSessionFactory().getCurrentSession(); Transaction t = session.beginTransaction(); String sequel = "Select max(JAdmAppExemptionId) from JAdmAppExemption"; Query q = session.createQuery(sequel); List currentSeq = q.list(); if(currentSeq == null){ return appId; }else{ appId = (Long)currentSeq.get(0); return appId+1; } }catch(Exception exc){ System.out.print("Unable to get latestID"); exc.printStackTrace(); } return 0; }
Some cumulative features are supported: see the manual