Announcement Announcement Module
Collapse
No announcement yet.
Spring Data Jpa interface getSingleResult() Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data Jpa interface getSingleResult()

    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.
    Last edited by purpeli; Apr 22nd, 2013, 08:26 AM. Reason: Formatted
Working...
X