diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/EntityRowMapper.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/EntityRowMapper.java index daf660146..8ecaa161b 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/EntityRowMapper.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/EntityRowMapper.java @@ -21,8 +21,8 @@ import java.sql.SQLException; import org.springframework.data.relational.core.mapping.AggregatePath; import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; import org.springframework.data.relational.domain.RowDocument; +import org.springframework.data.util.TypeInformation; import org.springframework.jdbc.core.RowMapper; -import org.springframework.lang.Nullable; /** * Maps a {@link ResultSet} to an entity of type {@code T}, including entities referenced. This {@link RowMapper} might @@ -37,26 +37,24 @@ import org.springframework.lang.Nullable; */ public class EntityRowMapper implements RowMapper { - private final RelationalPersistentEntity entity; - private final AggregatePath path; + private final TypeInformation typeInformation; private final JdbcConverter converter; - private final @Nullable Identifier identifier; + private final Identifier identifier; - @SuppressWarnings("unchecked") - public EntityRowMapper(AggregatePath path, JdbcConverter converter, Identifier identifier) { + private EntityRowMapper(TypeInformation typeInformation, JdbcConverter converter, Identifier identifier) { - this.entity = (RelationalPersistentEntity) path.getLeafEntity(); - this.path = path; + this.typeInformation = typeInformation; this.converter = converter; this.identifier = identifier; } - public EntityRowMapper(RelationalPersistentEntity entity, JdbcConverter converter) { + @SuppressWarnings("unchecked") + public EntityRowMapper(AggregatePath path, JdbcConverter converter, Identifier identifier) { + this(((RelationalPersistentEntity) path.getRequiredLeafEntity()).getTypeInformation(), converter, identifier); + } - this.entity = entity; - this.path = null; - this.converter = converter; - this.identifier = null; + public EntityRowMapper(RelationalPersistentEntity entity, JdbcConverter converter) { + this(entity.getTypeInformation(), converter, Identifier.empty()); } @Override @@ -64,9 +62,7 @@ public class EntityRowMapper implements RowMapper { RowDocument document = RowDocumentResultSetExtractor.toRowDocument(resultSet); - return identifier == null // - ? converter.readAndResolve(entity.getTypeInformation(), document, Identifier.empty()) // - : converter.readAndResolve(entity.getTypeInformation(), document, identifier); + return converter.readAndResolve(typeInformation, document, identifier); } }