Skip to content

Reading converter executed for 'countBy' method #1732

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
jaeykweon opened this issue Feb 3, 2024 · 2 comments
Closed

Reading converter executed for 'countBy' method #1732

jaeykweon opened this issue Feb 3, 2024 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@jaeykweon
Copy link

Situation

While using Reading Converter for converting data, I found some query method which works in 3.2.1 but throws error in 3.2.2.

You can compare 3.2.1 and 3.2.2 in example code.

Error Description

Codes added at R2dbcEntityTemplate.java in 3.2.2 handle 'count query method' differently compared to 3.2.1.

You can see changes below or Comparing changes

// 3.2.1
if(simpleType) {
    rowMapper = dataAccessStrategy.getRowMapper(resultType);
} else {
... // else logic
}

// 3.2.2
if(converter instanceof AbstractRelationalConverter relationalConverter
    && relationalConverter.getConversions().hasCustomReadTarget(Row.class,  entityType)) {

    ConversionService conversionService = relationalConverter.getConversionService();
    rowMapper = (row, rowMetadata) -> (T) conversionService.convert(row, entityType);
} else if(simpleType) {
    rowMapper = dataAccessStrategy.getRowMapper(resultType);
} else {
... // same as 3.2.1
}

We have countByCategory(category: Category): Long for example.

In 3.2.1, R2dbcEntityTemplate checks whether return type is simple type or not at first. So query result doesn't enter ReadingConverter.

In 3.2.2 however, it checks whether custom converter exists or not before checking simple type. In this time, query result enters ReadingConverter. Query result have only one column, and error occurs.

How to test

Use example code.

Suggestion

I think switching first and second statement may solve this problem.

if(simpleType) {
    rowMapper = dataAccessStrategy.getRowMapper(resultType);
} else if(converter instanceof AbstractRelationalConverter relationalConverter
    && relationalConverter.getConversions().hasCustomReadTarget(Row.class, entityType)) {

    ConversionService conversionService = relationalConverter.getConversionService();
    rowMapper = (row, rowMetadata) -> (T) conversionService.convert(row, entityType);
} else {
... // same as 3.2.1
}

ETC

Sorry for my poor English. I hope you understand what I want to say.

@jaeykweon jaeykweon changed the title Count query method except 'repository default' works in 3.1.1, but throws error in 3.2.2. Maybe bug? Count query method except 'repository default' works in 3.2.1, but throws error in 3.2.2. Maybe bug? Feb 3, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 3, 2024
@mp911de mp911de changed the title Count query method except 'repository default' works in 3.2.1, but throws error in 3.2.2. Maybe bug? Reading converter executed for 'countBy' method Feb 5, 2024
@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Feb 5, 2024
@mp911de
Copy link
Member

mp911de commented Feb 5, 2024

This should be fixed via #1723, care to retest against the latest 3.2.x snapshots?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 5, 2024
@jaeykweon
Copy link
Author

It works at 3.2.3-snapshot. Thank you!

@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Feb 5, 2024
@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants