From d57068b41046a5ca66f27370ace46d7b93835c01 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Wed, 22 Aug 2018 10:07:20 +0200 Subject: [PATCH] #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. --- .../src/main/java/example/springdata/jdbc/jooq/Category.java | 2 ++ .../java/example/springdata/jdbc/jooq/SimpleEntityTests.java | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/jdbc/jooq/src/main/java/example/springdata/jdbc/jooq/Category.java b/jdbc/jooq/src/main/java/example/springdata/jdbc/jooq/Category.java index 0782cfd3..f7c9ba13 100644 --- a/jdbc/jooq/src/main/java/example/springdata/jdbc/jooq/Category.java +++ b/jdbc/jooq/src/main/java/example/springdata/jdbc/jooq/Category.java @@ -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; diff --git a/jdbc/jooq/src/test/java/example/springdata/jdbc/jooq/SimpleEntityTests.java b/jdbc/jooq/src/test/java/example/springdata/jdbc/jooq/SimpleEntityTests.java index 450a8695..87f711a9 100644 --- a/jdbc/jooq/src/test/java/example/springdata/jdbc/jooq/SimpleEntityTests.java +++ b/jdbc/jooq/src/test/java/example/springdata/jdbc/jooq/SimpleEntityTests.java @@ -51,11 +51,10 @@ public class SimpleEntityTests { Category buildings = new Category(null, "Buildings", null, AgeGroup._12andOlder); // save categories - repository.saveAll(asList(cars, buildings)); + Iterable 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'.");