【发布时间】:2010-09-24 18:14:50
【问题描述】:
hibernate HQL查询是否支持使用select min、max、count等sql函数?
喜欢:
select min(p.age) from person p
谢谢
【问题讨论】:
标签: nhibernate hibernate hql min
hibernate HQL查询是否支持使用select min、max、count等sql函数?
喜欢:
select min(p.age) from person p
谢谢
【问题讨论】:
标签: nhibernate hibernate hql min
是的,HQL 支持 min()、max() 和 count()。
请参阅 Hibernate 文档中的 aggregate functions。
【讨论】:
这就是我在 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;
}
【讨论】:
支持一些聚合函数:查看manual
【讨论】: