Fix dynamic query method projection.

Query methods returning dynamic projections based on a Class argument now properly apply projection conversion. Previously, classes not seen by the mapping context were skipped and that caused projecting query methods to return the actual entity type.

Closes #607
This commit is contained in:
Mark Paluch
2021-06-22 11:21:53 +02:00
parent b8709a6824
commit 02ba403d07
2 changed files with 15 additions and 5 deletions

View File

@@ -94,10 +94,6 @@ interface R2dbcQueryExecution {
return source;
}
if (!mappingContext.hasPersistentEntityFor(returnedType.getReturnedType())) {
return source;
}
if (ReflectionUtils.isVoid(returnedType.getReturnedType())) {
if (source instanceof Mono) {

View File

@@ -142,7 +142,7 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
}).verifyComplete();
}
@Test // gh-475
@Test // gh-475, gh-607
void shouldFindApplyingInterfaceProjection() {
shouldInsertNewItems();
@@ -154,6 +154,14 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
.consumeNextWith(actual -> {
assertThat(actual).contains("SCHAUFELRADBAGGER", "FORSCHUNGSSCHIFF");
}).verifyComplete();
repository.findBy(WithName.class) //
.map(WithName::getName) //
.collectList() //
.as(StepVerifier::create) //
.consumeNextWith(actual -> {
assertThat(actual).contains("SCHAUFELRADBAGGER", "FORSCHUNGSSCHIFF");
}).verifyComplete();
}
@Test // gh-475
@@ -375,6 +383,8 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
Flux<Named> findAsProjection();
<T> Flux<T> findBy(Class<T> theClass);
@Query("SELECT name from legoset")
Flux<LegoDto> findAsDtoProjection();
@@ -442,4 +452,8 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
interface Named {
String getName();
}
interface WithName {
String getName();
}
}