Skip to content

Commit e93a84f

Browse files
committed
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
1 parent a9de60f commit e93a84f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryExecution.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ public Object convert(Object source) {
9494
return source;
9595
}
9696

97-
if (!mappingContext.hasPersistentEntityFor(returnedType.getReturnedType())) {
98-
return source;
99-
}
100-
10197
if (ReflectionUtils.isVoid(returnedType.getReturnedType())) {
10298

10399
if (source instanceof Mono) {

src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void shouldFindItemsByNameLike() {
142142
}).verifyComplete();
143143
}
144144

145-
@Test // gh-475
145+
@Test // gh-475, gh-607
146146
void shouldFindApplyingInterfaceProjection() {
147147

148148
shouldInsertNewItems();
@@ -154,6 +154,14 @@ void shouldFindApplyingInterfaceProjection() {
154154
.consumeNextWith(actual -> {
155155
assertThat(actual).contains("SCHAUFELRADBAGGER", "FORSCHUNGSSCHIFF");
156156
}).verifyComplete();
157+
158+
repository.findBy(WithName.class) //
159+
.map(WithName::getName) //
160+
.collectList() //
161+
.as(StepVerifier::create) //
162+
.consumeNextWith(actual -> {
163+
assertThat(actual).contains("SCHAUFELRADBAGGER", "FORSCHUNGSSCHIFF");
164+
}).verifyComplete();
157165
}
158166

159167
@Test // gh-475
@@ -375,6 +383,8 @@ interface LegoSetRepository extends ReactiveCrudRepository<LegoSet, Integer> {
375383

376384
Flux<Named> findAsProjection();
377385

386+
<T> Flux<T> findBy(Class<T> theClass);
387+
378388
@Query("SELECT name from legoset")
379389
Flux<LegoDto> findAsDtoProjection();
380390

@@ -442,4 +452,8 @@ public LegoDto(String name, String unknown) {
442452
interface Named {
443453
String getName();
444454
}
455+
456+
interface WithName {
457+
String getName();
458+
}
445459
}

0 commit comments

Comments
 (0)