From my little personal experience, if you are looking for an object in your repo, for example, Id or Name, the named query method returns an object of type T , but if the results of your repo are not found, it will return null.
Methods that can return more than one item will create an empty List<T> (not null) collection.
Some documentation here: http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repository-query-keywords
Appendix D: Repository Return Request Types
Supported return request types Return request types:
T Unique entity. Expects the query method to return one result maximum. If no result is found, null is returned equally. More than one result will raise an IncorrectResultSizeDataAccessException.
Iterator Iterator.
It seems that only when the type of the return type is of type T , is it the only one that indicates that null is returned if there are no matches.
source share