Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -143,7 +143,7 @@ protected List<Expression> getSelectList(SelectSpec selectSpec, @Nullable Relati
List<Expression> mapped = new ArrayList<>(selectList.size());

for (Expression expression : selectList) {
mapped.add(updateMapper.getMappedObject(expression, entity));
mapped.addAll(updateMapper.getMappedObjects(expression, entity));
}

return mapped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -34,6 +34,7 @@
import java.util.stream.Collectors;

import org.reactivestreams.Publisher;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
Expand All @@ -60,7 +61,6 @@
import org.springframework.data.r2dbc.mapping.event.BeforeSaveCallback;
import org.springframework.data.relational.core.conversion.AbstractRelationalConverter;
import org.springframework.data.relational.core.mapping.PersistentPropertyTranslator;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.query.Criteria;
Expand Down Expand Up @@ -621,18 +621,20 @@ private <T> Mono<T> doUpdate(T entity, SqlIdentifier tableName) {
return maybeCallBeforeSave(entityToUse, outboundRow, tableName) //
.flatMap(onBeforeSave -> {

Map<SqlIdentifier, Object> idValues = new HashMap<>();
((RelationalMappingContext) mappingContext).getAggregatePath(persistentEntity).getTableInfo()
.idColumnInfos().forEach((ap, ci) -> idValues.put(ci.name(), outboundRow.remove(ci.name())));
Map<SqlIdentifier, Object> idValues = new LinkedHashMap<>();
List<SqlIdentifier> identifierColumns = dataAccessStrategy.getIdentifierColumns(persistentEntity.getType());
Assert.state(!identifierColumns.isEmpty(), entityToUse + " has no Identifier. Update is not possible.");

identifierColumns.forEach(sqlIdentifier -> {
idValues.put(sqlIdentifier, outboundRow.remove(sqlIdentifier));
});

persistentEntity.forEach(p -> {
if (p.isInsertOnly()) {
outboundRow.remove(p.getColumnName());
}
});

Assert.state(!idValues.isEmpty(), entityToUse + " has no id. Update is not possible");

Criteria criteria = null;
for (Map.Entry<SqlIdentifier, Object> idAndValue : idValues.entrySet()) {
if (criteria == null) {
Expand Down
Loading