Skip to content

Commit d57068b

Browse files
committed
#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.
1 parent f643209 commit d57068b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

jdbc/jooq/src/main/java/example/springdata/jdbc/jooq/Category.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import lombok.Data;
1919

20+
import lombok.experimental.Wither;
2021
import org.springframework.data.annotation.Id;
2122

2223
/**
@@ -28,6 +29,7 @@
2829
@Data
2930
public class Category {
3031

32+
@Wither
3133
private final @Id Long id;
3234
private String name, description;
3335
private AgeGroup ageGroup;

jdbc/jooq/src/test/java/example/springdata/jdbc/jooq/SimpleEntityTests.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ public void exerciseRepositoryForSimpleEntity() {
5151
Category buildings = new Category(null, "Buildings", null, AgeGroup._12andOlder);
5252

5353
// save categories
54-
repository.saveAll(asList(cars, buildings));
54+
Iterable<Category> saved = repository.saveAll(asList(cars, buildings));
5555
Output.list(repository.findAll(), "`Cars` and `Buildings` got saved");
5656

57-
assertThat(cars.getId()).isNotNull();
58-
assertThat(buildings.getId()).isNotNull();
57+
assertThat(saved).extracting(c -> c.getId()).isNotNull();
5958

6059
// update one
6160
buildings.setDescription("Famous and impressive buildings incl. the 'bike shed'.");

0 commit comments

Comments
 (0)