Does hibernate HQL queries support using select min, max, count and other sql functions?
hibernate HQL查询是否支持使用select min,max,count和其他sql函数?
like:
select min(p.age) from person p
从人p中选择min(p.age)
Thanks
3 个解决方案
#1
12
Yes, min()
, max()
and count()
are supported in HQL.
是的,HQL支持min(),max()和count()。
see aggregate functions in the Hibernate Doc.
请参阅Hibernate Doc中的聚合函数。
#2
5
thats how I am using max in Hibernate :
多数民众赞成我如何在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;
}
#1
12
Yes, min()
, max()
and count()
are supported in HQL.
是的,HQL支持min(),max()和count()。
see aggregate functions in the Hibernate Doc.
请参阅Hibernate Doc中的聚合函数。
#2
5
thats how I am using max in Hibernate :
多数民众赞成我如何在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;
}