diff --git a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java index 61b0558b6..7873c6d12 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java @@ -58,7 +58,7 @@ import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Order; import org.springframework.data.jpa.domain.JpaSort.JpaOrder; import org.springframework.data.mapping.PropertyPath; -import org.springframework.data.util.StreamUtils; +import org.springframework.data.util.Streamable; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -185,13 +185,11 @@ public abstract class QueryUtils { public static String getExistsQueryString(String entityName, String countQueryPlaceHolder, Iterable idAttributes) { - String baseQuery = String.format(COUNT_QUERY_STRING, countQueryPlaceHolder, entityName); - - String whereClause = StreamUtils.createStreamFromIterator(idAttributes.iterator()) - .map(idAttribute -> String.format(EQUALS_CONDITION_STRING, "x", idAttribute, idAttribute)) + String whereClause = Streamable.of(idAttributes).stream() // + .map(idAttribute -> String.format(EQUALS_CONDITION_STRING, "x", idAttribute, idAttribute)) // .collect(Collectors.joining(" AND ", " WHERE ", "")); - return baseQuery + whereClause; + return String.format(COUNT_QUERY_STRING, countQueryPlaceHolder, entityName) + whereClause; } /** diff --git a/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java b/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java index 1e65fe621..3a479882b 100644 --- a/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java @@ -15,10 +15,12 @@ */ package org.springframework.data.jpa.repository.query; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; import static org.springframework.data.jpa.repository.query.QueryUtils.*; +import java.util.Collections; import java.util.Set; import org.hamcrest.Matcher; @@ -385,6 +387,13 @@ public class QueryUtilsUnitTests { assertThat(aliases, contains("authority")); } + @Test // DATAJPA-1171 + public void doesNotContainStaticClauseInExistsQuery() { + + assertThat(QueryUtils.getExistsQueryString("entity", "x", Collections.singleton("id"))) // + .endsWith("WHERE x.id = :id"); + } + private static void assertCountQuery(String originalQuery, String countQuery) { assertThat(createCountQueryFor(originalQuery), is(countQuery)); }