Skip to content

Commit fc5f6d7

Browse files
committed
DATAJDBC-557 - Fix save on entity only have id and collections.
1 parent 0b05a06 commit fc5f6d7

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
@@ -114,7 +114,7 @@ public <T> Object insert(T instance, Class<T> domainType, Identifier identifier)
114114
identifier.forEach((name, value, type) -> addConvertedPropertyValue(parameterSource, name, value, type));
115115

116116
Object idValue = getIdValueOrNull(instance, persistentEntity);
117-
if (idValue != null) {
117+
if (idValue != null || parameterSource.getIdentifiers().isEmpty()) {
118118

119119
RelationalPersistentProperty idProperty = persistentEntity.getRequiredIdProperty();
120120
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)