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:
@@ -94,10 +94,6 @@ interface R2dbcQueryExecution {
|
||||
return source;
|
||||
}
|
||||
|
||||
if (!mappingContext.hasPersistentEntityFor(returnedType.getReturnedType())) {
|
||||
return source;
|
||||
}
|
||||
|
||||
if (ReflectionUtils.isVoid(returnedType.getReturnedType())) {
|
||||
|
||||
if (source instanceof Mono) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user