hibernate HQL查询是否支持使用select min,max,count和其他sql函数?
喜欢:
select min(p.age) from person p
谢谢
是的,min()
,max()
和count()
在HQL支持.
请参阅Hibernate Doc中的聚合函数.
多数民众赞成我如何在Hibernate中使用max:
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; }