@3/7/2023
엔티티 추가
•
ERD 보면서 엔티티 추가함
•
ERD 자체에도 있는 잘못된 사항들 수정하면서 크로스 체크가 됨
package dev.gyuray.forum.domain;
import javax.persistence.Embeddable;
@Embeddable
public class Address {
private String city;
private String street;
private String zipcode;
}
Java
복사
package dev.gyuray.forum.domain;
import javax.persistence.*;
import java.time.LocalDateTime;
@Entity
public class Comment {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
@ManyToOne
@JoinColumn(name = "post_id")
private Post post;
private LocalDateTime regDate;
private String content;
}
Java
복사
package dev.gyuray.forum.domain;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Entity
public class Post {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Comment> comment = new ArrayList<>();
private String title;
private LocalDateTime regDate;
private Integer view;
}
Java
복사
package dev.gyuray.forum.domain;
public enum Role {
USER, ADMIN
}
Java
복사
package dev.gyuray.forum.domain;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Entity
public class User {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "user")
private List<Post> posts = new ArrayList<>();
@OneToMany(mappedBy = "user")
private List<Comment> comments = new ArrayList<>();
private String name;
@Embedded
private Address address;
private String email;
@Enumerated
private Role role;
private LocalDateTime regDate;
}
Java
복사