diff --git a/src/main/java/friend/spring/domain/Category.java b/src/main/java/friend/spring/domain/Category.java new file mode 100644 index 0000000..b08d7dd --- /dev/null +++ b/src/main/java/friend/spring/domain/Category.java @@ -0,0 +1,27 @@ +package friend.spring.domain; + +import friend.spring.domain.common.BaseEntity; +import lombok.*; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Category extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, length = 10) + private String name; + + @Builder.Default + @OneToMany(mappedBy = "category") + private List postList = new ArrayList<>(); +} diff --git a/src/main/java/friend/spring/domain/Post.java b/src/main/java/friend/spring/domain/Post.java index 447f9fe..6e85c70 100644 --- a/src/main/java/friend/spring/domain/Post.java +++ b/src/main/java/friend/spring/domain/Post.java @@ -57,6 +57,9 @@ public class Post extends BaseEntity { @JoinColumn(name = "user_id") private User user; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private Category postCategory; // 부모 글 정의 // 고민후기 원글 아이디 @ManyToOne(fetch = FetchType.LAZY)