Since it seems that HQL (createQuery) doesn't support scalar queries, I used a raw query via 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 doesn't fail, but it seems to be returning a list with an infinite number of results? This doesn't make sense... Any idea why I am getting this?
Even better yet, is there a better, more elegant way, of getting the intended scalar, without having to confuse whoever maintains my code with a "list" (that should always contain one element)?