Browse Source

Ignore books in JSON output; define SQL fetch & cascade types for book

list
Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.2-alpha
Pekka Helenius 4 years ago
parent
commit
87ccddc9eb
1 changed files with 11 additions and 6 deletions
  1. +11
    -6
      bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java

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

@ -4,14 +4,15 @@ package com.fjordtek.bookstore.model;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator; import javax.persistence.SequenceGenerator;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity @Entity
@ -21,7 +22,7 @@ public class Category {
// Primary key value in database // Primary key value in database
@Id @Id
@GeneratedValue( @GeneratedValue(
strategy = GenerationType.AUTO,
strategy = GenerationType.IDENTITY,
generator = "categoryIdGenerator" generator = "categoryIdGenerator"
) )
@SequenceGenerator( @SequenceGenerator(
@ -35,11 +36,15 @@ public class Category {
// Attributes with hard-coded constraints // Attributes with hard-coded constraints
private String name; private String name;
@JsonBackReference
// Omit from Jackson JSON serialization
//@JsonBackReference(value = "books")
@JsonIgnore
@OneToMany( @OneToMany(
mappedBy = "category"
//fetch = FetchType.LAZY,
//cascade = CascadeType.ALL
mappedBy = "category",
fetch = FetchType.LAZY,
cascade = CascadeType.ALL
//targetEntity = Book.class
) )
private List<Book> books; private List<Book> books;


Loading…
Cancel
Save