Untitled
unknown
plain_text
3 years ago
1.1 kB
6
Indexable
//My models
// Comment entity
@Data
@Entity
@ToString
@Table(name = "TB_COMMENT")
public class Comment implements Serializable {
@Id
private Integer id;
private String name;
private String email;
private String body;
@JoinColumn(name="post_id", nullable=false)
private Post post;
}
// Post entity
@Data
@Entity
@Table(name = "TB_POST")
public class Post implements Serializable {
@Id
private Integer id;
private String title;
private String body;
@OneToMany(targetEntity=Comment.class, mappedBy="post", fetch=FetchType.EAGER, cascade = CascadeType.ALL)
private List<Comment> comments = new ArrayList<>();
@JoinColumn(name="user_id", nullable=false)
private User user;
}
//User entity
@Data
@Entity
@ToString
@Table(name = "TB_USER")
public class User implements Serializable {
@Id
private int id;
private String name;
@OneToMany(targetEntity=Post.class, mappedBy="user", fetch=FetchType.EAGER, cascade = CascadeType.ALL)
List<Post> posts = new ArrayList<>();
}Editor is loading...