Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Spring Data Jpa interface getSingleResult()

$
0
0
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:

Code:

public interface UserRepository extends JpaRepository<User, Integer> {
        @Query("SELECT u from User u where u.passportId=:passportId")
        User findUserByPassportId(@Param("passportId") String passportId
}

But this returns NULL, if none is found.

Viewing all articles
Browse latest Browse all 297

Trending Articles