look likes Hibernate have not this syntax,that is 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;
}
}
There are a few problems with this....
IFNULL
is COALESCE
in HQL (IFNULL equivalent in Hibernate Query Language?.)list().get(0)
.session.createSqlQuery()
.IdentifierGenerator
(http://blog.anorakgirl.co.uk/2009/01/custom-hibernate-sequence-generator-for-id-field/).Regardless though, the code would be...
public int MaxIdenx() {
int max = (Integer)session
.createQuery("SELECT COALESCE(MAX(empId), 0) FROM Emp")
.uniqueResult();
return max + 1;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With