Can javax.persistence.Query.getResultList() return null?

后端 未结 7 1881
心在旅途
心在旅途 2020-12-02 15:19

And if so, under what circumstances?

Javadoc and JPA spec says nothing.

7条回答
  •  感动是毒
    2020-12-02 15:27

    You are right. JPA specification says nothing about it. But Java Persistence with Hibernate book, 2nd edition, says:

    If the query result is empty, a null is returned

    Hibernate JPA implementation (Entity Manager) return null when you call query.getResultList() with no result.

    UPDATE

    As pointed out by some users, it seems that a newest version of Hibernate returns an empty list instead.

    An empty list is returned in Eclipselink as well when no results are found.

提交回复
热议问题