Hello there. Does hibernate HQL queries support using select min, max, count and other sql functions?
like
select min(p.age) from person p
Thanks
Hello there. Does hibernate HQL queries support using select min, max, count and other sql functions?
like
select min(p.age) from person p
Thanks
thats how I am using 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;
}
And how can I execute more complex query, for example:
SELECT count(*) AS c, t.status AS s from ProductEntity AS t GROUP BY t.status
The question is how to cast result of execution to Java objects? Can I create simple (Long, Long) object and cast each result to it?