|
23 | 23 | import reactor.core.publisher.Mono;
|
24 | 24 |
|
25 | 25 | import java.util.Collections;
|
26 |
| -import java.util.HashMap; |
| 26 | +import java.util.LinkedHashMap; |
27 | 27 | import java.util.LinkedHashSet;
|
28 | 28 | import java.util.List;
|
29 | 29 | import java.util.Map;
|
|
34 | 34 | import java.util.stream.Collectors;
|
35 | 35 |
|
36 | 36 | import org.reactivestreams.Publisher;
|
| 37 | + |
37 | 38 | import org.springframework.beans.BeansException;
|
38 | 39 | import org.springframework.beans.factory.BeanFactory;
|
39 | 40 | import org.springframework.beans.factory.BeanFactoryAware;
|
|
60 | 61 | import org.springframework.data.r2dbc.mapping.event.BeforeSaveCallback;
|
61 | 62 | import org.springframework.data.relational.core.conversion.AbstractRelationalConverter;
|
62 | 63 | import org.springframework.data.relational.core.mapping.PersistentPropertyTranslator;
|
63 |
| -import org.springframework.data.relational.core.mapping.RelationalMappingContext; |
64 | 64 | import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
|
65 | 65 | import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
|
66 | 66 | import org.springframework.data.relational.core.query.Criteria;
|
@@ -621,18 +621,20 @@ private <T> Mono<T> doUpdate(T entity, SqlIdentifier tableName) {
|
621 | 621 | return maybeCallBeforeSave(entityToUse, outboundRow, tableName) //
|
622 | 622 | .flatMap(onBeforeSave -> {
|
623 | 623 |
|
624 |
| - Map<SqlIdentifier, Object> idValues = new HashMap<>(); |
625 |
| - ((RelationalMappingContext) mappingContext).getAggregatePath(persistentEntity).getTableInfo() |
626 |
| - .idColumnInfos().forEach((ap, ci) -> idValues.put(ci.name(), outboundRow.remove(ci.name()))); |
| 624 | + Map<SqlIdentifier, Object> idValues = new LinkedHashMap<>(); |
| 625 | + List<SqlIdentifier> identifierColumns = dataAccessStrategy.getIdentifierColumns(persistentEntity.getType()); |
| 626 | + Assert.state(!identifierColumns.isEmpty(), entityToUse + " has no Identifier. Update is not possible."); |
| 627 | + |
| 628 | + identifierColumns.forEach(sqlIdentifier -> { |
| 629 | + idValues.put(sqlIdentifier, outboundRow.remove(sqlIdentifier)); |
| 630 | + }); |
627 | 631 |
|
628 | 632 | persistentEntity.forEach(p -> {
|
629 | 633 | if (p.isInsertOnly()) {
|
630 | 634 | outboundRow.remove(p.getColumnName());
|
631 | 635 | }
|
632 | 636 | });
|
633 | 637 |
|
634 |
| - Assert.state(!idValues.isEmpty(), entityToUse + " has no id. Update is not possible"); |
635 |
| - |
636 | 638 | Criteria criteria = null;
|
637 | 639 | for (Map.Entry<SqlIdentifier, Object> idAndValue : idValues.entrySet()) {
|
638 | 640 | if (criteria == null) {
|
|
0 commit comments