I have a Spring app that is using Hibernate and the Spring Data JPA's CrudRepository
. Everything seems to work properly if the data that was queried for exists in the database. However, if there is a query that returns no result, the CrudRepository
returns null
and I get a NullPointerException
. So for example http://localhost:8080/api/id=3
if there is a row with id 3 in the database it works fine. If there isn't a row with id of 3 it fails with a:
there was an unexpected error (type=Internal Server Error, status=500)
On the client side and a NullPointerException
on the server side.
What is the proper way of dealing with a simple case of a "No Results" query?