look likes Hibernate don't have this syntax, is that right? 
public int MaxIdenx() { int max = 0; String hql = "select ifnull(max(empId),0)from Emp"; Query query = session.createQuery(hql); List currentSeq = query.list(); if (currentSeq == null) { return max; } else { max = (Integer) currentSeq.get(0); return max + 1; } }
source share