Search code examples
javaspringjpaspring-data-jpa

NonUniqueResultException thrown when using spring jpa "findtop"


I am using Spring JPA, and NonUniqueResultException throw when I use "findTop" keyword

Java source:

Optional<ClassA> findTopByXXXOrderByIdDesc(String xxx);

Then get the exception:

exceptionType = org.springframework.dao.IncorrectResultSizeDataAccessException exception = result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements

Any one know what happen?


Solution

  • Could you please check the version of your Spring Data JPA. Note that Top and First are available since 1.7.1.RELEASE.