Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions