Skip to content

Commit 8c30022

Browse files
schaudermp911de
authored andcommitted
Do not throw IncorrectUpdateSemanticsDataAccessException on zero updated rows.
When an update results in 0 updated rows (without optimistic locking) 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 Original pull request: #2185
1 parent 120ead7 commit 8c30022

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
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
@@ -334,12 +334,7 @@ private <T> RelationalPersistentEntity<T> getRequiredPersistentEntity(Class<T> t
334334
}
335335

336336
private <T> void updateWithoutVersion(DbAction.UpdateRoot<T> update) {
337-
338-
if (!accessStrategy.update(update.getEntity(), update.getEntityType())) {
339-
340-
throw new IncorrectUpdateSemanticsDataAccessException(
341-
String.format(UPDATE_FAILED, update.getEntity(), getIdFrom(update)));
342-
}
337+
accessStrategy.update(update.entity(), update.getEntityType());
343338
}
344339

345340
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,7 @@ void updateFailedRootDoesNotExist() {
583583
LegoSet entity = new LegoSet();
584584
entity.id = 100L; // does not exist in the database
585585

586-
assertThatExceptionOfType(DbActionExecutionException.class) //
587-
.isThrownBy(() -> template.save(entity)) //
588-
.withCauseInstanceOf(IncorrectUpdateSemanticsDataAccessException.class);
586+
assertThatCode(() -> template.save(entity)).doesNotThrowAnyException();
589587
}
590588

591589
@Test // DATAJDBC-112
@@ -1185,7 +1183,7 @@ void saveAndUpdateAggregateWithIdAndNullVersion() {
11851183
aggregate.setVersion(null);
11861184
aggregate.setId(23L);
11871185

1188-
assertThatThrownBy(() -> template.save(aggregate)).isInstanceOf(DbActionExecutionException.class);
1186+
assertThatCode(() -> template.save(aggregate)).doesNotThrowAnyException();
11891187
}
11901188

11911189
@Test // DATAJDBC-462

0 commit comments

Comments
 (0)