Browse Source

Determine data types for database; add column definitions

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.2-alpha
Pekka Helenius 4 years ago
parent
commit
a2fcecfe8c
4 changed files with 36 additions and 13 deletions
  1. +16
    -8
      bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java
  2. +12
    -3
      bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java
  3. +2
    -1
      bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java
  4. +6
    -1
      bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java

+ 16
- 8
bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java View File

@ -43,7 +43,11 @@ public class Author {
private Long id;
//////////
@Column(name = "firstname", nullable = false)
@Column(
name = "firstname",
nullable = false,
columnDefinition = "NVARCHAR(" + strMax + ")"
)
@Size(
min = strMin, max = strMax,
message = "First name length must be " + strMin + "-" + strMax + " characters"
@ -58,7 +62,11 @@ public class Author {
private String firstName;
//////////
@Column(name = "lastname", nullable = false)
@Column(
name = "lastname",
nullable = false,
columnDefinition = "NVARCHAR(" + strMax + ")"
)
@Size(
min = strMin, max = strMax,
message = "Last name length must be " + strMin + "-" + strMax + " characters"
@ -74,14 +82,14 @@ public class Author {
// Omit from Jackson JSON serialization
//@JsonBackReference(value = "books")
@JsonIgnore
@OneToMany(
mappedBy = "author",
// We consider EAGER FetchType for updatable tables, i.e. when adding new author
fetch = FetchType.EAGER,
cascade = CascadeType.ALL,
targetEntity = Book.class
mappedBy = "author",
fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
targetEntity = Book.class
//orphanRemoval = true
)
private List<Book> books;


+ 12
- 3
bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java View File

@ -99,7 +99,10 @@ public class Book {
// Attributes with hard-coded constraints
//////////
@Column(nullable = false)
@Column(
nullable = false,
columnDefinition = "NVARCHAR(" + strMax + ")"
)
@Size(
min = strMin, max = strMax,
message = "Title length must be " + strMin + "-" + strMax + " characters"
@ -139,7 +142,10 @@ public class Book {
// private Timestamp year;
// ...
// TODO: Consider allowing 0 value if year is not known
@Column(nullable = true)
@Column(
nullable = false,
columnDefinition = "INT(4)"
)
@Min(
value = yearMin,
message = "Minimum allowed year: " + yearMin
@ -148,7 +154,10 @@ public class Book {
private int year;
//////////
@Column(unique = true, nullable = false)
@Column(
unique = true,
nullable = false
)
@NotBlank(
message = "Fill the ISBN code form"
)


+ 2
- 1
bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java View File

@ -75,7 +75,8 @@ public class BookHash {
name = "hash_id",
unique = true,
columnDefinition = "CHAR(32)",
updatable = false
updatable = false,
nullable = false
)
private String hashId;


+ 6
- 1
bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java View File

@ -5,6 +5,7 @@ package com.fjordtek.bookstore.model;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
@ -34,12 +35,16 @@ public class Category {
////////////////////
// Attributes with hard-coded constraints
@Column(
nullable = false,
columnDefinition = "NVARCHAR(50)"
)
private String name;
// Omit from Jackson JSON serialization
//@JsonBackReference(value = "books")
@JsonIgnore
@OneToMany(
mappedBy = "category",
fetch = FetchType.LAZY,


Loading…
Cancel
Save