Skip to content

Fix R2dbcEntityTemplate.getRowsFetchSpec(…) to use the correct Converter for result type conversion #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
* @author Jens Schauder
* @author Jose Luis Leon
* @author Robert Heim
* @author Sebastian Wieland
* @since 1.1
*/
public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAware, ApplicationContextAware {
Expand Down Expand Up @@ -821,10 +822,10 @@ public <T> RowsFetchSpec<T> getRowsFetchSpec(DatabaseClient.GenericExecuteSpec e

// Bridge-code: Consider Converter<Row, T> until we have fully migrated to RowDocument
if (converter instanceof AbstractRelationalConverter relationalConverter
&& relationalConverter.getConversions().hasCustomReadTarget(Row.class, entityType)) {
&& relationalConverter.getConversions().hasCustomReadTarget(Row.class, resultType)) {

ConversionService conversionService = relationalConverter.getConversionService();
rowMapper = (row, rowMetadata) -> (T) conversionService.convert(row, entityType);
rowMapper = (row, rowMetadata) -> (T) conversionService.convert(row, resultType);
} else if (simpleType) {
rowMapper = dataAccessStrategy.getRowMapper(resultType);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.Row;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.util.Arrays;
Expand Down Expand Up @@ -51,6 +52,7 @@
* Integration tests for {@link ConvertedRepository} that uses {@link Converter}s on entity-level.
*
* @author Mark Paluch
* @author Sebastian Wieland
*/
@ExtendWith(SpringExtension.class)
public class ConvertingR2dbcRepositoryIntegrationTests {
Expand Down Expand Up @@ -122,8 +124,26 @@ void shouldInsertAndReadItems() {
}).verifyComplete();
}

interface ConvertedRepository extends ReactiveCrudRepository<ConvertedEntity, Integer> {
@Test
void shouldNotUseConverterForCountQueries() {
ConvertedEntity entity = new ConvertedEntity();
entity.name = "name";

repository.save(entity) //
.as(StepVerifier::create) //
.expectNextCount(1) //
.verifyComplete();

repository.countWithCustomQuery() //
.as(StepVerifier::create) //
.consumeNextWith(actual -> {
assertThat(actual).isEqualTo(1L);
}).verifyComplete();
}

interface ConvertedRepository extends ReactiveCrudRepository<ConvertedEntity, Integer> {
@Query("SELECT COUNT(*) FROM CONVERTED_ENTITY")
Mono<Long> countWithCustomQuery();
}

static class ConvertedEntity {
Expand Down