#395 - Correcting handling of immutable properties.

If properties are final they need to have a matching argument in the persistence constructor or a matching "Wither".
Otherwise trying to set them results in an exception.

Id Properties additionally need a Wither if a generated Id from the database is supposed to get set.
This commit is contained in:
Jens Schauder
2018-08-22 10:07:20 +02:00
parent f6432092fa
commit d57068b410
2 changed files with 4 additions and 3 deletions

View File

@@ -17,6 +17,7 @@ package example.springdata.jdbc.jooq;
import lombok.Data;
import lombok.experimental.Wither;
import org.springframework.data.annotation.Id;
/**
@@ -28,6 +29,7 @@ import org.springframework.data.annotation.Id;
@Data
public class Category {
@Wither
private final @Id Long id;
private String name, description;
private AgeGroup ageGroup;

View File

@@ -51,11 +51,10 @@ public class SimpleEntityTests {
Category buildings = new Category(null, "Buildings", null, AgeGroup._12andOlder);
// save categories
repository.saveAll(asList(cars, buildings));
Iterable<Category> saved = repository.saveAll(asList(cars, buildings));
Output.list(repository.findAll(), "`Cars` and `Buildings` got saved");
assertThat(cars.getId()).isNotNull();
assertThat(buildings.getId()).isNotNull();
assertThat(saved).extracting(c -> c.getId()).isNotNull();
// update one
buildings.setDescription("Famous and impressive buildings incl. the 'bike shed'.");