From f28977edbb6a203eeaabc8c4c42c292b11414ddd Mon Sep 17 00:00:00 2001 From: Yeseo Date: Fri, 19 Apr 2024 12:09:31 +0900 Subject: [PATCH] refactor: Add `@ManyToOne` mapping (#63) --- .../com/beotkkot/qtudy/domain/comments/Comments.java | 12 ++++++++---- .../java/com/beotkkot/qtudy/domain/quiz/Review.java | 6 ++++-- .../java/com/beotkkot/qtudy/domain/tags/Tags.java | 5 ++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/beotkkot/qtudy/domain/comments/Comments.java b/src/main/java/com/beotkkot/qtudy/domain/comments/Comments.java index 2ca4235..6620a0a 100644 --- a/src/main/java/com/beotkkot/qtudy/domain/comments/Comments.java +++ b/src/main/java/com/beotkkot/qtudy/domain/comments/Comments.java @@ -1,5 +1,7 @@ package com.beotkkot.qtudy.domain.comments; +import com.beotkkot.qtudy.domain.posts.Posts; +import com.beotkkot.qtudy.domain.user.Users; import jakarta.persistence.*; import lombok.*; @@ -13,11 +15,13 @@ public class Comments { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long commentId; - @Column(nullable = false) - private Long postId; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "post_id", nullable = false) + private Posts post; - @Column(nullable = false) - private Long userUid; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private Users user; @Column(columnDefinition = "TEXT") private String content; diff --git a/src/main/java/com/beotkkot/qtudy/domain/quiz/Review.java b/src/main/java/com/beotkkot/qtudy/domain/quiz/Review.java index acef716..4e11bfd 100644 --- a/src/main/java/com/beotkkot/qtudy/domain/quiz/Review.java +++ b/src/main/java/com/beotkkot/qtudy/domain/quiz/Review.java @@ -1,5 +1,6 @@ package com.beotkkot.qtudy.domain.quiz; +import com.beotkkot.qtudy.domain.user.Users; import jakarta.persistence.*; import lombok.*; @@ -13,8 +14,9 @@ public class Review { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(nullable = false) - private Long userId; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private Users user; @Column(nullable = false) private Long postId; diff --git a/src/main/java/com/beotkkot/qtudy/domain/tags/Tags.java b/src/main/java/com/beotkkot/qtudy/domain/tags/Tags.java index 7d942c0..88f0577 100644 --- a/src/main/java/com/beotkkot/qtudy/domain/tags/Tags.java +++ b/src/main/java/com/beotkkot/qtudy/domain/tags/Tags.java @@ -1,5 +1,6 @@ package com.beotkkot.qtudy.domain.tags; +import com.beotkkot.qtudy.domain.category.Category; import jakarta.persistence.*; import lombok.*; @@ -18,7 +19,9 @@ public class Tags { private int count; // 태그 언급 횟수 - private Long categoryId; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private Category category; public void increaseTagCount() { this.count++;