How to use mysql syntax like ifnull (max (Id), 0) in Hibernate

look likes Hibernate don't have this syntax, is that right? enter image description here

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; } } 
+6
source share
1 answer

There are several problems with this ....

Despite this, the code will ...

 public int MaxIdenx() { int max = (Integer)session .createQuery("SELECT COALESCE(MAX(empId), 0) FROM Emp") .uniqueResult(); return max + 1; } 
+11
source

All Articles