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

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

And if so, under what circumstances?

Javadoc and JPA spec says nothing.

ベストアンサー1

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.

おすすめ記事