What does EntityManager.getSingleResult()
return for a COUNT query?
So.. what is the precise runtime type of foo?
Object foo = em.createQuer
return query.getSingleResult() != null ? Integer.parseInt(query.getSingleResult().toString()) : 0;
Second call query.getSingleResult() will throw org.hibernate.SessionException: Session is closed!
To avoid the org.hibernate.SessionException: Session is closed! use as below
Object obj = query.getSingleResult();
if (obj != null) {
Integer result = Integer.parseInt(obj.toString());
return result;
}
return Integer.valueOf(0);