diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 44ffc727b..063093858 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -40,8 +40,6 @@ import java.util.Map; import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import org.springframework.data.domain.Example; import org.springframework.data.domain.KeysetScrollPosition; @@ -246,14 +244,8 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation idsCollection = StreamSupport.stream(ids.spliterator(), false) - .collect(Collectors.toCollection(ArrayList::new)); - query.setParameter("ids", idsCollection); - } + Collection idCollection = toCollection(ids); + query.setParameter("ids", idCollection); applyQueryHints(query); @@ -414,7 +406,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation idCollection = Streamable.of(ids).toList(); + Collection idCollection = toCollection(ids); ByIdsSpecification specification = new ByIdsSpecification<>(entityInformation); TypedQuery query = getQuery(specification, Sort.unsorted()); @@ -925,6 +917,11 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation Collection toCollection(Iterable ids) { + return ids instanceof Collection c ? c : Streamable.of(ids).toList(); + } + /** * Executes a count query and transparently sums up all values returned. *