The complete example codes is here, https://github.com/hantsy/spring6-sandbox/blob/master/data-jdbc
There is a entity class implements Persistable and use the isNew to identify if it is a new entity.
@Table("persistable_posts")
@Setter
@Getter
@ToString
public class PersistablePost implements Persistable<UUID> {
@Id
UUID id;
String title;
String content;
@Version
Long version;
@Override
public boolean isNew() {
return getId() == null;
}
}
When I set a id and isNew returns true, thus calling template.save will try to update the entity that is not existed, and throw a DbActionExecutionException.
@Test
public void givenEntityImplementsPersistableInterface_whenIsNewReturnTrue_andSave_thenExecuteUpdateActionAndThrowsException() {
var data = new PersistablePost();
data.setTitle("test");
data.setContent("test content");
data.setId(UUID.randomUUID());
// the id is set, then `isNew` returns a `true`, `save` method will execute a `update` action.
assertThatThrownBy(() -> this.template.save(data)).isInstanceOf(DbActionExecutionException.class);
}
These codes work well in the last milestone, when upgrading the latest milestone aligned with Spring 6.0.0-M4. The test failed.
java.lang.IllegalArgumentException: The root aggregate cannot be updated because the version property is null.
at org.springframework.util.Assert.notNull(Assert.java:201)
at org.springframework.data.jdbc.core.JdbcAggregateTemplate.prepareVersionForUpdate(JdbcAggregateTemplate.java:356)
at org.springframework.data.jdbc.core.JdbcAggregateTemplate.lambda$save$1(JdbcAggregateTemplate.java:146)
...(78 remaining lines not displayed - this can be changed with Assertions.setMaxStackTraceElementsDisplayed)
The complete example codes is here, https://github.com/hantsy/spring6-sandbox/blob/master/data-jdbc
There is a entity class implements
Persistableand use theisNewto identify if it is a new entity.When I set a id and
isNewreturns true, thus callingtemplate.savewill try to update the entity that is not existed, and throw aDbActionExecutionException.These codes work well in the last milestone, when upgrading the latest milestone aligned with Spring 6.0.0-M4. The test failed.