diff --git a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java index 3eb0762eef..582e587026 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java @@ -176,7 +176,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/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java index a4a438e857..08e8ff927c 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -2621,6 +2621,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/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java b/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java index 721123ca19..9350b01848 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java +++ b/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();