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; private Long id;
////////// //////////
@Column(name = "firstname", nullable = false)
@Column(
name = "firstname",
nullable = false,
columnDefinition = "NVARCHAR(" + strMax + ")"
)
@Size( @Size(
min = strMin, max = strMax, min = strMin, max = strMax,
message = "First name length must be " + strMin + "-" + strMax + " characters" message = "First name length must be " + strMin + "-" + strMax + " characters"
@ -58,7 +62,11 @@ public class Author {
private String firstName; private String firstName;
////////// //////////
@Column(name = "lastname", nullable = false)
@Column(
name = "lastname",
nullable = false,
columnDefinition = "NVARCHAR(" + strMax + ")"
)
@Size( @Size(
min = strMin, max = strMax, min = strMin, max = strMax,
message = "Last name length must be " + strMin + "-" + strMax + " characters" message = "Last name length must be " + strMin + "-" + strMax + " characters"
@ -74,14 +82,14 @@ public class Author {
// Omit from Jackson JSON serialization // Omit from Jackson JSON serialization
//@JsonBackReference(value = "books") //@JsonBackReference(value = "books")
@JsonIgnore @JsonIgnore
@OneToMany( @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; 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 // Attributes with hard-coded constraints
////////// //////////
@Column(nullable = false)
@Column(
nullable = false,
columnDefinition = "NVARCHAR(" + strMax + ")"
)
@Size( @Size(
min = strMin, max = strMax, min = strMin, max = strMax,
message = "Title length must be " + strMin + "-" + strMax + " characters" message = "Title length must be " + strMin + "-" + strMax + " characters"
@ -139,7 +142,10 @@ public class Book {
// private Timestamp year; // private Timestamp year;
// ... // ...
// TODO: Consider allowing 0 value if year is not known // TODO: Consider allowing 0 value if year is not known
@Column(nullable = true)
@Column(
nullable = false,
columnDefinition = "INT(4)"
)
@Min( @Min(
value = yearMin, value = yearMin,
message = "Minimum allowed year: " + yearMin message = "Minimum allowed year: " + yearMin
@ -148,7 +154,10 @@ public class Book {
private int year; private int year;
////////// //////////
@Column(unique = true, nullable = false)
@Column(
unique = true,
nullable = false
)
@NotBlank( @NotBlank(
message = "Fill the ISBN code form" 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", name = "hash_id",
unique = true, unique = true,
columnDefinition = "CHAR(32)", columnDefinition = "CHAR(32)",
updatable = false
updatable = false,
nullable = false
) )
private String hashId; 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 java.util.List;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
@ -34,12 +35,16 @@ public class Category {
//////////////////// ////////////////////
// Attributes with hard-coded constraints // Attributes with hard-coded constraints
@Column(
nullable = false,
columnDefinition = "NVARCHAR(50)"
)
private String name; private String name;
// Omit from Jackson JSON serialization // Omit from Jackson JSON serialization
//@JsonBackReference(value = "books") //@JsonBackReference(value = "books")
@JsonIgnore @JsonIgnore
@OneToMany( @OneToMany(
mappedBy = "category", mappedBy = "category",
fetch = FetchType.LAZY, fetch = FetchType.LAZY,


Loading…
Cancel
Save