Browse Source

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
3.5.x
Jens Schauder 4 weeks ago committed by Mark Paluch
parent
commit
8c30022ecc
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 7
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java
  2. 6
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java

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

@ -334,12 +334,7 @@ class JdbcAggregateChangeExecutionContext { @@ -334,12 +334,7 @@ class JdbcAggregateChangeExecutionContext {
}
private <T> void updateWithoutVersion(DbAction.UpdateRoot<T> update) {
if (!accessStrategy.update(update.getEntity(), update.getEntityType())) {
throw new IncorrectUpdateSemanticsDataAccessException(
String.format(UPDATE_FAILED, update.getEntity(), getIdFrom(update)));
}
accessStrategy.update(update.entity(), update.getEntityType());
}
private <T> void updateWithVersion(DbAction.UpdateRoot<T> update) {

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

@ -583,9 +583,7 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests { @@ -583,9 +583,7 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests {
LegoSet entity = new LegoSet();
entity.id = 100L; // does not exist in the database
assertThatExceptionOfType(DbActionExecutionException.class) //
.isThrownBy(() -> template.save(entity)) //
.withCauseInstanceOf(IncorrectUpdateSemanticsDataAccessException.class);
assertThatCode(() -> template.save(entity)).doesNotThrowAnyException();
}
@Test // DATAJDBC-112
@ -1185,7 +1183,7 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests { @@ -1185,7 +1183,7 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests {
aggregate.setVersion(null);
aggregate.setId(23L);
assertThatThrownBy(() -> template.save(aggregate)).isInstanceOf(DbActionExecutionException.class);
assertThatCode(() -> template.save(aggregate)).doesNotThrowAnyException();
}
@Test // DATAJDBC-462

Loading…
Cancel
Save