Skip to content

ResultSetExtractor can not use default row mapper [DATAJDBC-620] #840

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
spring-projects-issues opened this issue Oct 22, 2020 · 1 comment
Assignees
Labels
in: repository Repositories abstraction type: bug A general bug

Comments

@spring-projects-issues
Copy link

denniseffing opened DATAJDBC-620 and commented

A CustomResultSetExtractor should either be instantiated using a constructor with a RowMapper parameter OR using a constructor without any parameters if the RowMapper-constructor doesn't exist:

https://github.com/spring-projects/spring-data-jdbc/blob/f23b9876429fd33438a06192f2b9b23f49a4d048/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java#L143-L170

This functionality is tested using the following unit test: https://github.com/spring-projects/spring-data-jdbc/blob/f23b9876429fd33438a06192f2b9b23f49a4d048/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQueryUnitTests.java#L120-L136

The issue is that the executor of the StringBasedJdbcQuery is initialized using a rowMapper set to null if the rowMapper equals the defaultRowMapper:

public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOperations operations,
		@Nullable RowMapper<?> defaultRowMapper, JdbcConverter converter) {

	super(queryMethod, operations, defaultRowMapper);

	this.queryMethod = queryMethod;
	this.converter = converter;

	executor = Lazy.of(() -> {
		RowMapper<Object> rowMapper = determineRowMapper(defaultRowMapper);
		return getQueryExecution( //
			queryMethod, //
			determineResultSetExtractor(rowMapper != defaultRowMapper ? rowMapper : null), //
			rowMapper //
	);});

This does not make sense at all, because the above mentioned RowMapper-constructor is only called it if exists anyways. This prevents injecting the default RowMapper into a custom ResultSetExtractor entirely. It will always be set to null


Affects: 2.0.4 (Neumann SR4), 2.0.5 (Neumann SR5), 2.1 RC2 (2020.0.0), 2.1 GA (2020.0.0)

Referenced from: pull request #256

@spring-projects-issues spring-projects-issues added type: bug A general bug in: repository Repositories abstraction labels Dec 31, 2020
@mp911de mp911de assigned mp911de and unassigned christophstrobl Jan 18, 2021
@mp911de mp911de added this to the 2.1.4 (2020.0.4) milestone Jan 18, 2021
@mp911de
Copy link
Member

mp911de commented Jan 18, 2021

Fixed via #256.

@mp911de mp911de closed this as completed Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository Repositories abstraction type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants