Avoid noop update for Id only aggregates.

Closes #1309
This commit is contained in:
Jens Schauder
2022-08-25 14:18:32 +02:00
parent 345f12bac9
commit d95b5592a7
3 changed files with 20 additions and 1 deletions

View File

@@ -139,7 +139,12 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
*/
@Override
public <S> boolean update(S instance, Class<S> domainType) {
return operations.update(sql(domainType).getUpdate(), sqlParametersFactory.forUpdate(instance, domainType)) != 0;
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.forUpdate(instance, domainType);
if (parameterSource.size() <= 1) {
return true; // returning true, because conceptually the one row was correctly updated
}
return operations.update(sql(domainType).getUpdate(), parameterSource) != 0;
}
/*

View File

@@ -81,4 +81,8 @@ class SqlIdentifierParameterSource extends AbstractSqlParameterSource {
addValue(identifier, others.getValue(name), others.getSqlType(name));
}
}
int size() {
return namesToValues.size();
}
}

View File

@@ -983,6 +983,16 @@ class JdbcAggregateTemplateIntegrationTests {
assertThat(template.save(entity).id).isNotNull();
}
@Test // GH-1309
void updateIdOnlyAggregate() {
WithIdOnly entity = new WithIdOnly();
assertThat(template.save(entity).id).isNotNull();
template.save(entity);
}
@Test // GH-1232
@EnabledOnFeature(IS_HSQL)
void beforeSaveCallbackEffectsAreVisibleForInsert() {