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

后端 未结 8 1024
北海茫月
北海茫月 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:33

    NB : there's a difference between JQPL and Native query

    Query query = em.createQuery("SELECT COUNT(p) FROM PersonEntity p " );
    

    query.getSingleResult().getClass().getCanonicalName() --> java.lang.Long

    Query query = em.createNativeQuery("SELECT COUNT(*) FROM PERSON " );
    

    query.getSingleResult().getClass().getCanonicalName() --> java.math.BigInteger

提交回复
热议问题