diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java index 7584cd6994..6777a4e8b9 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java @@ -164,7 +164,7 @@ protected CriteriaQuery complete(@Nullable Predicate predicate selections.add(toExpressionRecursively(root, path, true).alias(property)); } - Class typeToRead = returnedType.getTypeToRead(); + Class typeToRead = returnedType.getReturnedType(); query = typeToRead.isInterface() ? query.multiselect(selections) diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java index e481be31fa..a07ea34028 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -2630,6 +2630,14 @@ void readsDtoProjections() { assertThat(repository.findAllDtoProjectedBy()).hasSize(4); } + @Test // GH-2408, GH-2363 + void readsDerivedInterfaceProjections() { + + flushTestUsers(); + + assertThat(repository.findAllInterfaceProjectedBy()).hasSize(4); + } + private Page executeSpecWithSort(Sort sort) { flushTestUsers(); diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java index 32b0b36767..6570a5ea87 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java @@ -614,6 +614,9 @@ Page findAllOrderedBySpecialNameMultipleParams(@Param("name") String name, // #2363 List findAllDtoProjectedBy(); + // GH-2408 + List findAllInterfaceProjectedBy(); + interface RolesAndFirstname { String getFirstname();