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
pull/2189/head
Jens Schauder 4 weeks ago committed by Mark Paluch
parent
commit
b06d348fc4
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. 5
      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

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

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

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

Loading…
Cancel
Save