Read domain type when returning an implemented interface from repository query methods.
We now read the domain type instead of trying to materialize an interface if the type returned from the query method is implemented by the domain object handled by the repository. Closes #519
This commit is contained in:
@@ -122,6 +122,10 @@ public abstract class AbstractR2dbcQuery implements RepositoryQuery {
|
||||
|
||||
ReturnedType returnedType = resultProcessor.getReturnedType();
|
||||
|
||||
if (returnedType.getReturnedType().isAssignableFrom(returnedType.getDomainType())) {
|
||||
return returnedType.getDomainType();
|
||||
}
|
||||
|
||||
return returnedType.isProjecting() ? returnedType.getDomainType() : returnedType.getReturnedType();
|
||||
}
|
||||
|
||||
|
||||
@@ -347,11 +347,16 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
|
||||
Mono<Integer> countByNameContains(String namePart);
|
||||
}
|
||||
|
||||
public interface Buildable {
|
||||
|
||||
String getName();
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Table("legoset")
|
||||
@NoArgsConstructor
|
||||
static class LegoSet extends Lego {
|
||||
static class LegoSet extends Lego implements Buildable {
|
||||
String name;
|
||||
Integer manual;
|
||||
|
||||
|
||||
@@ -137,8 +137,19 @@ public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIn
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // gh-519
|
||||
public void shouldReturnEntityThroughInterface() {
|
||||
|
||||
shouldInsertNewItems();
|
||||
|
||||
repository.findByName("SCHAUFELRADBAGGER").map(Buildable::getName).as(StepVerifier::create)
|
||||
.expectNext("SCHAUFELRADBAGGER").verifyComplete();
|
||||
}
|
||||
|
||||
interface H2LegoSetRepository extends LegoSetRepository {
|
||||
|
||||
Mono<Buildable> findByName(String name);
|
||||
|
||||
@Override
|
||||
@Query("SELECT name FROM legoset")
|
||||
Flux<Named> findAsProjection();
|
||||
|
||||
Reference in New Issue
Block a user