Using Min, Max, and Count in HQL

Does hibernate support HQL queries with select min, max, count and other sql functions?

like

select min (p.age) from person p

thanks

+6
hibernate nhibernate hql min
source share
3 answers

Yes, min() , max() and count() supported in HQL.

see aggregate functions in the Hibernate Doc.

+12
source share

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; } 
+5
source share

Some cumulative features are supported: see the manual

+2
source share

All Articles