Skip to content

Commit 4a3097e

Browse files
committed
DATAJDBC-557 - Fix save on entity only have id and collections.
1 parent 597663c commit 4a3097e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public <T> Object insert(T instance, Class<T> domainType, Identifier identifier)
115115
identifier.forEach((name, value, type) -> addConvertedPropertyValue(parameterSource, name, value, type));
116116

117117
Object idValue = getIdValueOrNull(instance, persistentEntity);
118-
if (idValue != null) {
118+
if (idValue != null || parameterSource.getIdentifiers().isEmpty()) {
119119

120120
RelationalPersistentProperty idProperty = persistentEntity.getRequiredIdProperty();
121121
addConvertedPropertyValue(parameterSource, idProperty, idValue, idProperty.getColumnName());

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java

+4
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ private UpdateBuilder.UpdateWhereAndOr createBaseUpdate() {
610610
getBindMarker(columnName))) //
611611
.collect(Collectors.toList());
612612

613+
if (assignments.isEmpty()) {
614+
assignments.add(Assignments.value(getIdColumn(), getBindMarker(entity.getIdColumn())));
615+
}
616+
613617
return Update.builder() //
614618
.table(table) //
615619
.set(assignments) //

0 commit comments

Comments
 (0)