2323
2424import org .springframework .core .convert .ConversionService ;
2525import org .springframework .core .convert .converter .Converter ;
26- import org .springframework .data .convert .ClassGeneratingEntityInstantiator ;
27- import org .springframework .data .convert .EntityInstantiator ;
26+ import org .springframework .data .convert .EntityInstantiators ;
2827import org .springframework .data .jdbc .mapping .model .JdbcMappingContext ;
2928import org .springframework .data .jdbc .mapping .model .JdbcPersistentEntity ;
3029import org .springframework .data .jdbc .mapping .model .JdbcPersistentProperty ;
3534import org .springframework .data .mapping .model .ConvertingPropertyAccessor ;
3635import org .springframework .data .mapping .model .ParameterValueProvider ;
3736import org .springframework .jdbc .core .RowMapper ;
38- import org .springframework .lang .Nullable ;
39- import org .springframework .util .Assert ;
4037
4138/**
4239 * Maps a ResultSet to an entity of type {@code T}, including entities referenced.
@@ -50,7 +47,7 @@ public class EntityRowMapper<T> implements RowMapper<T> {
5047 private static final Converter ITERABLE_OF_ENTRY_TO_MAP_CONVERTER = new IterableOfEntryToMapConverter ();
5148
5249 private final JdbcPersistentEntity <T > entity ;
53- private final EntityInstantiator instantiator = new ClassGeneratingEntityInstantiator ();
50+
5451 private final ConversionService conversions ;
5552 private final JdbcMappingContext context ;
5653 private final DataAccessStrategy accessStrategy ;
@@ -98,17 +95,17 @@ public T mapRow(ResultSet resultSet, int rowNumber) throws SQLException {
9895 }
9996
10097 private T createInstance (ResultSet rs ) {
101- return instantiator .createInstance (entity , new ResultSetParameterValueProvider (rs , entity , conversions , "" ));
102- }
10398
99+ return context .getInstantiatorFor (entity ) //
100+ .createInstance (entity , new ResultSetParameterValueProvider (rs , entity , conversions , "" ));
101+ }
104102
105103 /**
106104 * Read a single value or a complete Entity from the {@link ResultSet} passed as an argument.
107105 *
108106 * @param resultSet the {@link ResultSet} to extract the value from. Must not be {@code null}.
109107 * @param property the {@link JdbcPersistentProperty} for which the value is intended. Must not be {@code null}.
110108 * @param prefix to be used for all column names accessed by this method. Must not be {@code null}.
111- *
112109 * @return the value read from the {@link ResultSet}. May be {@code null}.
113110 */
114111 private Object readFrom (ResultSet resultSet , JdbcPersistentProperty property , String prefix ) {
@@ -138,8 +135,8 @@ private <S> S readEntityFrom(ResultSet rs, PersistentProperty<?> property) {
138135 return null ;
139136 }
140137
141- S instance = instantiator . createInstance (entity ,
142- new ResultSetParameterValueProvider (rs , entity , conversions , prefix ));
138+ S instance = context . getInstantiatorFor (entity ) //
139+ . createInstance ( entity , new ResultSetParameterValueProvider (rs , entity , conversions , prefix ));
143140
144141 PersistentPropertyAccessor accessor = entity .getPropertyAccessor (instance );
145142 ConvertingPropertyAccessor propertyAccessor = new ConvertingPropertyAccessor (accessor , conversions );
0 commit comments