diff --git a/src/main/java/org/springframework/data/repository/query/QueryMethod.java b/src/main/java/org/springframework/data/repository/query/QueryMethod.java index c4ccb10b8..b8aa6df80 100644 --- a/src/main/java/org/springframework/data/repository/query/QueryMethod.java +++ b/src/main/java/org/springframework/data/repository/query/QueryMethod.java @@ -181,13 +181,11 @@ public class QueryMethod { return true; } - if (QueryExecutionConverters.supports(unwrappedReturnType) - && QueryExecutionConverters.isSingleValue(unwrappedReturnType)) { - return false; + if (QueryExecutionConverters.supports(unwrappedReturnType)) { + return !QueryExecutionConverters.isSingleValue(unwrappedReturnType); } - return org.springframework.util.ClassUtils.isAssignable(Iterable.class, unwrappedReturnType) - || unwrappedReturnType.isArray(); + return ClassTypeInformation.from(unwrappedReturnType).isCollectionLike(); } /** @@ -289,7 +287,9 @@ public class QueryMethod { Assert.notEmpty(types, "Types must not be null or empty!"); TypeInformation returnType = ClassTypeInformation.fromReturnTypeOf(method); - returnType = QueryExecutionConverters.isSingleValue(returnType.getType()) ? returnType.getRequiredComponentType() + + returnType = QueryExecutionConverters.isSingleValue(returnType.getType()) // + ? returnType.getRequiredComponentType() // : returnType; for (Class type : types) { diff --git a/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java b/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java index 94caea045..a3a154666 100755 --- a/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java +++ b/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java @@ -38,6 +38,7 @@ import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.projection.SpelAwareProxyProjectionFactory; import org.springframework.data.repository.Repository; import org.springframework.data.repository.core.RepositoryMetadata; +import org.springframework.data.repository.core.support.AbstractRepositoryMetadata; import org.springframework.data.repository.core.support.DefaultRepositoryMetadata; import org.springframework.data.util.Version; @@ -230,6 +231,15 @@ public class QueryMethodUnitTests { assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isTrue(); } + @Test // DATACMNS-1300 + public void doesNotConsiderMethodForIterableAggregateACollectionQuery() throws Exception { + + RepositoryMetadata metadata = AbstractRepositoryMetadata.getMetadata(ContainerRepository.class); + Method method = ContainerRepository.class.getMethod("someMethod"); + + assertThat(new QueryMethod(method, metadata, factory).isCollectionQuery()).isFalse(); + } + interface SampleRepository extends Repository { String pagingMethodWithInvalidReturnType(Pageable pageable); @@ -283,4 +293,14 @@ public class QueryMethodUnitTests { class SpecialUser extends User { } + + // DATACMNS-1300 + + class Element {} + + abstract class Container implements Iterable {} + + interface ContainerRepository extends Repository { + Container someMethod(); + } }