Is it possible to use Spring Data JPA interface to query only for a single Result ?
(javax.persistence.Query.getSingleResult(), and throw an exception if none is found)
Like this:
But this returns NULL, if none is found.
(javax.persistence.Query.getSingleResult(), and throw an exception if none is found)
Like this:
Code:
public interface UserRepository extends JpaRepository<User, Integer> {
@Query("SELECT u from User u where u.passportId=:passportId")
User findUserByPassportId(@Param("passportId") String passportId
}