-
Notifications
You must be signed in to change notification settings - Fork 373
Closed
Description
Clemens Hahn opened DATAJDBC-481 and commented
I think there is a problem with @Version
-Fields in immutable entities.
I found the test org.springframework.data.jdbc.core.JdbcAggregateTemplateIntegrationTests#saveAndUpdateAggregateWithImmutableVersion
. This test is green on my machine.
I extended the test: the return value of template.save(reloadedAggregate)
does not hold the incremented version number (problem occurs only at the second call!).
Please have a look at the following adjusted test:
@Test // DATAJDBC-219 Test that immutable version attribute works as expected.
public void saveAndUpdateAggregateWithImmutableVersion() {
AggregateWithImmutableVersion aggregate = new AggregateWithImmutableVersion(null, null);
aggregate = template.save(aggregate);
assertThat(aggregate.version).isEqualTo(1L); // works
Long id = aggregate.getId();
AggregateWithImmutableVersion reloadedAggregate = template.findById(id, aggregate.getClass());
assertThat(reloadedAggregate.getVersion()).describedAs("version field should initially have the value 1")
.isEqualTo(1L);
AggregateWithImmutableVersion saved = template.save(reloadedAggregate);
AggregateWithImmutableVersion updatedAggregate = template.findById(id, aggregate.getClass());
assertThat(saved.version)
.describedAs("returned by save(): "+ saved + " vs. returned by findById(): " + updatedAggregate)
.isEqualTo(updatedAggregate.version); // fails
// [..]
}
This adjusted test fails with
org.junit.ComparisonFailure: [returned by save(): JdbcAggregateTemplateIntegrationTests.AggregateWithImmutableVersion(id=1, version=1) vs. returned by findById(): JdbcAggregateTemplateIntegrationTests.AggregateWithImmutableVersion(id=1, version=2)]
Expected :2L
Actual :1L
I hope I did not make a mistake and that the current bahavior is not the expected one.
I attached a Patch-File with this adjusted test.
Attachments:
- immutable-save-version.patch (1.46 kB)
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug