вот как я использую max в 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;
}