From b06d348fc4e9a10810dee6b008f17431ed47feea Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Fri, 21 Nov 2025 13:43:00 +0100 Subject: [PATCH] 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 --- .../jdbc/core/JdbcAggregateChangeExecutionContext.java | 7 +------ .../AbstractJdbcAggregateTemplateIntegrationTests.java | 5 ++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java index b1f33efca..c4a6e022d 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java @@ -348,12 +348,7 @@ class JdbcAggregateChangeExecutionContext { } private void updateWithoutVersion(DbAction.UpdateRoot 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 void updateWithVersion(DbAction.UpdateRoot update) { diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java index a4e987721..a7234ba9f 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java @@ -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 { aggregate.setVersion(null); aggregate.setId(23L); - assertThatThrownBy(() -> template.save(aggregate)).isInstanceOf(IncorrectUpdateSemanticsDataAccessException.class); + assertThatCode(() -> template.save(aggregate)).doesNotThrowAnyException(); } @Test // DATAJDBC-462