From 967396b23de524e929b20cad66e91b1e47f86690 Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Sat, 19 Sep 2020 00:39:30 +0300 Subject: [PATCH] Add more database constraints for BOOK table Signed-off-by: Pekka Helenius --- .../src/main/java/com/fjordtek/bookstore/model/Book.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java index 6b94def..d529b27 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java @@ -81,6 +81,7 @@ public class Book { // Attributes with hard-coded constraints ////////// + @Column(nullable = false) @Size( min = strMin, max = strMax, message = "Title length must be " + strMin + "-" + strMax + " characters" @@ -95,6 +96,7 @@ public class Book { private String title; ////////// + @Column(nullable = false) @Size( min = strMin, max = strMax, message = "Author length must be " + strMin + "-" + strMax + " characters" @@ -113,7 +115,8 @@ public class Book { // @DateTimeFormat(pattern = "yyyy") // private Timestamp year; // ... - + // TODO: Consider allowing 0 value if year is not known + @Column(nullable = true) @Min( value = yearMin, message = "Minimum allowed year: " + yearMin @@ -122,7 +125,7 @@ public class Book { private int year; ////////// - @Column(unique = true) + @Column(unique = true, nullable = false) @NotBlank( message = "Fill the ISBN code form" ) @@ -141,6 +144,7 @@ public class Book { ////////// @NumberFormat(style = Style.NUMBER, pattern = "#,###.###") + @Column(nullable = false) @Digits( integer = 3, fraction = 2, message = "Invalid price, possibly too many decimals"