diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 597b562d9..531fffb1a 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -262,7 +262,7 @@ public class SimpleJpaRepository implements JpaRepository, JpaSpec Assert.notNull(id, ID_MUST_NOT_BE_NULL); if (entityInformation.getIdAttribute() == null) { - return findById(id) != null; + return findById(id).isPresent(); } String placeholder = provider.getCountQueryPlaceholder(); @@ -287,7 +287,7 @@ public class SimpleJpaRepository implements JpaRepository, JpaSpec if (complexIdParameterValueDiscovered) { // fall-back to findById(id) which does the proper mapping for the parameter. - return findById(id) != null; + return findById(id).isPresent(); } query.setParameter(idAttributeName, idAttributeValue); @@ -455,8 +455,7 @@ public class SimpleJpaRepository implements JpaRepository, JpaSpec Class probeType = example.getProbeType(); TypedQuery query = getQuery(new ExampleSpecification<>(example), probeType, pageable); - return isUnpaged(pageable) ? new PageImpl<>(query.getResultList()) - : readPage(query, probeType, pageable, spec); + return isUnpaged(pageable) ? new PageImpl<>(query.getResultList()) : readPage(query, probeType, pageable, spec); } /* diff --git a/src/test/java/org/springframework/data/jpa/repository/RepositoryWithCompositeKeyTests.java b/src/test/java/org/springframework/data/jpa/repository/RepositoryWithCompositeKeyTests.java index 2206f0551..e11df5e77 100644 --- a/src/test/java/org/springframework/data/jpa/repository/RepositoryWithCompositeKeyTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/RepositoryWithCompositeKeyTests.java @@ -25,7 +25,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.domain.Page; @@ -210,7 +209,7 @@ public class RepositoryWithCompositeKeyTests { assertThat(result.get(1), is(emp1)); } - @Test // DATAJPA-527 + @Test // DATAJPA-527, DATAJPA-1148 public void testExistsWithIdClass() { IdClassExampleDepartment dep = new IdClassExampleDepartment(); @@ -227,6 +226,7 @@ public class RepositoryWithCompositeKeyTests { key.setEmpId(emp.getEmpId()); assertThat(employeeRepositoryWithIdClass.existsById(key), is(true)); + assertThat(employeeRepositoryWithIdClass.existsById(new IdClassExampleEmployeePK(0L, 0L)), is(false)); } @Test // DATAJPA-527