Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.sql.JDBCType;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.Predicate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -31,7 +31,6 @@
import org.springframework.data.jdbc.support.JdbcUtil;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PreferredConstructor;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
Expand Down Expand Up @@ -387,26 +386,16 @@ T mapRow() {
return createInstanceInternal(idValue);
}

private T populateProperties(T instance, @Nullable Object idValue) {
private T populateProperties(T instance, @Nullable Object idValue, Predicate<RelationalPersistentProperty> skipProperty) {

PersistentPropertyAccessor<T> propertyAccessor = getPropertyAccessor(entity, instance);

PreferredConstructor<T, RelationalPersistentProperty> persistenceConstructor = entity.getPersistenceConstructor();

for (RelationalPersistentProperty property : entity) {

if (persistenceConstructor != null && persistenceConstructor.isConstructorParameter(property)) {
if (skipProperty.test(property)) {
continue;
}

// skip absent simple properties
if (isSimpleProperty(property)) {

if (!propertyValueProvider.hasProperty(property)) {
continue;
}
}

Object value = readOrLoadProperty(idValue, property);
propertyAccessor.setProperty(property, value);
}
Expand Down Expand Up @@ -525,16 +514,29 @@ private Object readEntityFrom(RelationalPersistentProperty property) {

private T createInstanceInternal(@Nullable Object idValue) {

Set<RelationalPersistentProperty> constructorProperties = new HashSet<>();

T instance = createInstance(entity, parameter -> {

String parameterName = parameter.getName();

Assert.notNull(parameterName, "A constructor parameter name must not be null to be used with Spring Data JDBC");

RelationalPersistentProperty property = entity.getRequiredPersistentProperty(parameterName);
constructorProperties.add(property);

return readOrLoadProperty(idValue, property);
});
return populateProperties(instance, idValue);

return populateProperties(instance, idValue, property -> {

if (constructorProperties.contains(property)) {
return true;
}

// skip absent simple properties
return isSimpleProperty(property) && !propertyValueProvider.hasProperty(property);
});
}

}
Expand Down