What does EntityManager.getSingleResult() return for a COUNT query?
EntityManager.getSingleResult()
So.. what is the precise runtime type of foo?
Object foo = em.createQuer
COUNT(t) specifically returns java.lang.Long. When its appears on its own in this context it is returned as-is.
(In other contexts the Long generated by COUNT may be wrapped, but not today.)