Skip to content

Commit a1dc5f0

Browse files
committed
Ignore update count without version.
When an update results in 0 updated rows we now ignore it, instead of throwing an exception. The reason is that at least some databases return 0 when a row for updating was found, but none of the values changed. Closes #2176
1 parent 9b0ca43 commit a1dc5f0

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,7 @@ private <T> RelationalPersistentEntity<T> getRequiredPersistentEntity(Class<T> t
348348
}
349349

350350
private <T> void updateWithoutVersion(DbAction.UpdateRoot<T> update) {
351-
352-
if (!accessStrategy.update(update.entity(), update.getEntityType())) {
353-
354-
throw new IncorrectUpdateSemanticsDataAccessException(
355-
String.format(UPDATE_FAILED, update.entity(), getIdFrom(update)));
356-
}
351+
accessStrategy.update(update.entity(), update.getEntityType());
357352
}
358353

359354
private <T> void updateWithVersion(DbAction.UpdateRoot<T> update) {

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ void updateFailedRootDoesNotExist() {
579579
LegoSet entity = new LegoSet();
580580
entity.id = 100L; // does not exist in the database
581581

582-
assertThatExceptionOfType(IncorrectUpdateSemanticsDataAccessException.class) //
583-
.isThrownBy(() -> template.save(entity));
582+
assertThatCode(() -> template.save(entity)).doesNotThrowAnyException();
584583
}
585584

586585
@Test // DATAJDBC-112
@@ -1180,7 +1179,7 @@ void saveAndUpdateAggregateWithIdAndNullVersion() {
11801179
aggregate.setVersion(null);
11811180
aggregate.setId(23L);
11821181

1183-
assertThatThrownBy(() -> template.save(aggregate)).isInstanceOf(IncorrectUpdateSemanticsDataAccessException.class);
1182+
assertThatCode(() -> template.save(aggregate)).doesNotThrowAnyException();
11841183
}
11851184

11861185
@Test // DATAJDBC-462

0 commit comments

Comments
 (0)