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 f5f2fe1ef..adfc5e76b 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 @@ -530,8 +530,12 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation boolean exists(Example example) { - return !getQuery(new ExampleSpecification(example, escapeCharacter), example.getProbeType(), Sort.unsorted()) - .getResultList().isEmpty(); + Specification spec = new ExampleSpecification<>(example, this.escapeCharacter); + CriteriaQuery cq = this.em.getCriteriaBuilder().createQuery(Integer.class); + cq.select(this.em.getCriteriaBuilder().literal(1)); + applySpecificationToCriteria(spec, example.getProbeType(), cq); + TypedQuery query = applyRepositoryMethodMetadata(this.em.createQuery(cq)); + return query.setMaxResults(1).getSingleResult() != null; } /*