Skip to content

IllegalArgumentException: The root aggregate cannot be updated because the version property is null #1254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hantsy opened this issue May 30, 2022 · 2 comments
Assignees
Labels
type: regression A regression from a previous release

Comments

@hantsy
Copy link

hantsy commented May 30, 2022

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)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 30, 2022
@schauder
Copy link
Contributor

Please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.

The sample you currently provide contains lots of stuff that presumably has nothing to do with the problem at hand.

@schauder schauder added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels May 31, 2022
@hantsy
Copy link
Author

hantsy commented May 31, 2022

  1. Clone https://github.com/hantsy/spring6-sandbox or pick up data-jdbc by some Github browser extensions.
  2. Run docker compose up postgres in the root folder to serve database.
  3. Run JdbcAggregateTemplateTest

These sample projects are very simple, the best way is forking my project and run it on local machine yourself.

Or if you know well about the Persistable design, check errors from Github actions console,
https://github.com/hantsy/spring6-sandbox/runs/6655811112?check_suite_focus=true#step:7:443

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 31, 2022
@schauder schauder self-assigned this May 31, 2022
@schauder schauder added type: regression A regression from a previous release and removed status: feedback-provided Feedback has been provided labels May 31, 2022
schauder added a commit that referenced this issue Jun 1, 2022
When saving an Aggregate which is not new, but has a null version attribute we now throw a DbActionExecutionException, like we used to.

Closes #1254
schauder added a commit that referenced this issue Jun 1, 2022
schauder added a commit that referenced this issue Jun 1, 2022
schauder added a commit that referenced this issue Jun 1, 2022
When saving an Aggregate which is not new, but has a null version attribute we now throw a DbActionExecutionException, like we used to.

Closes #1254
schauder added a commit that referenced this issue Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

3 participants