From 77b89f7aa10566dfb1c840276a99487a93a0c6fd Mon Sep 17 00:00:00 2001 From: KIM MIN WOO <79193811+minwoo1999@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:21:43 +0900 Subject: [PATCH] refactor: Improve exists check in JpaQueryExecution by using getResultStream and findFirst --- .../data/jpa/repository/query/JpaQueryExecution.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java index 82482cd99c..aa7cf719a5 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java @@ -313,7 +313,10 @@ static class ExistsExecution extends JpaQueryExecution { @Override protected Object doExecute(AbstractJpaQuery query, JpaParametersParameterAccessor accessor) { - return !query.createQuery(accessor).getResultList().isEmpty(); + return query.createQuery(accessor) + .getResultStream() + .findFirst() + .isPresent(); } }