Browse Source

Fix + separate Id number generation for Book & Category

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.1-alpha
Pekka Helenius 4 years ago
parent
commit
df81977c3f
2 changed files with 14 additions and 2 deletions
  1. +7
    -1
      bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java
  2. +7
    -1
      bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java

+ 7
- 1
bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java View File

@ -13,6 +13,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Digits;
@ -65,7 +66,12 @@ public class Book {
@Id
@GeneratedValue(
strategy = GenerationType.AUTO
strategy = GenerationType.AUTO,
generator = "bookIdGenerator"
)
@SequenceGenerator(
name = "bookIdGenerator",
sequenceName = "bookIdSequence"
)
private long id;


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

@ -9,6 +9,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
@Entity
public class Category {
@ -17,7 +18,12 @@ public class Category {
// Primary key value in database
@Id
@GeneratedValue(
strategy = GenerationType.AUTO
strategy = GenerationType.AUTO,
generator = "categoryIdGenerator"
)
@SequenceGenerator(
name = "categoryIdGenerator",
sequenceName = "categoryIdSequence"
)
private long id;


Loading…
Cancel
Save