#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:
@@ -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;
|
||||
|
||||
@@ -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'.");
|
||||
|
||||
Reference in New Issue
Block a user