Since it seems that HQL (createQuery) does not support scalar queries, I used a raw query through createSQLQuery:
session.beginTransaction();
Query query = session.createSQLQuery("select nvl(max(id), 0) + 1 from empty_table_for_now");
session.getTransaction().commit();
List listL = query.list();
Iterator iterator = listL.iterator();
while (iterator.hasNext()) {
LOG.info("Infinite loop. This is disgusting!");
}
The query itself is not interrupted, but it looks like it returns a list with an infinite number of results? It makes no sense ... Any idea why I get this?
Even better, is there a better, more elegant way to get the intended scalar without getting confused with whoever supports my "list" code (which should always contain one element)?
source
share