What does JPA EntityManager.getSingleResult() return for a COUNT query?

后端 未结 8 1020
北海茫月
北海茫月 2021-02-01 02:43

What does EntityManager.getSingleResult() return for a COUNT query?

So.. what is the precise runtime type of foo?

Object foo = em.createQuer         


        
相关标签:
8条回答
  • 2021-02-01 03:36

    Native queries can return different objects for a COUNT based on the database driver; however, all those objects extend java.lang.Number, which implements the longValue() method.

    0 讨论(0)
  • 2021-02-01 03:36

    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.)

    0 讨论(0)
提交回复
热议问题