From d1e7f6d581708a28e751c8bed444acedf10d95eb Mon Sep 17 00:00:00 2001 From: yulmam <70622601+yulmam@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:42:58 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20cascade=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/edufocus/edufocus/report/entity/vo/Answer.java | 8 ++++++++ .../com/edufocus/edufocus/report/entity/vo/Report.java | 4 +++- .../com/edufocus/edufocus/report/entity/vo/ReportSet.java | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java index 53d0d35..969119a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java @@ -4,6 +4,8 @@ package com.edufocus.edufocus.report.entity.vo; import com.edufocus.edufocus.quiz.entity.Quiz; import jakarta.persistence.*; import lombok.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; @Entity @Getter @@ -17,15 +19,21 @@ public class Answer { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; + + @Column private String userAnswer; + + @Column private boolean isCorrect; @ManyToOne @JoinColumn(name = "report_id") + @OnDelete(action = OnDeleteAction.CASCADE) private Report report; @ManyToOne @JoinColumn(name = "quiz_id") + @OnDelete(action = OnDeleteAction.CASCADE) private Quiz quiz; } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java index 6e5d89a..9bb0440 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java @@ -46,13 +46,15 @@ public class Report { @ManyToOne @JoinColumn(name = "quizset_id") + @OnDelete(action = OnDeleteAction.CASCADE) private QuizSet quizSet; @ManyToOne @JoinColumn(name = "reportset_id") + @OnDelete(action = OnDeleteAction.CASCADE) private ReportSet reportSet; - @OneToMany(mappedBy = "report", cascade = CascadeType.REMOVE) + @OneToMany(mappedBy = "report") private List answers; public ReportResponse makeReportResponse() { diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/ReportSet.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/ReportSet.java index c23547c..f5beca6 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/ReportSet.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/ReportSet.java @@ -39,7 +39,7 @@ public class ReportSet { @Temporal(TemporalType.TIMESTAMP) private Date createAt; - @OneToMany(mappedBy = "reportSet", cascade = CascadeType.REMOVE) + @OneToMany(mappedBy = "reportSet") private List reports; @ManyToOne @@ -49,6 +49,7 @@ public class ReportSet { @ManyToOne @JoinColumn(name = "quizSet_id") + @OnDelete(action = OnDeleteAction.CASCADE) private QuizSet quizSet; public ReportSetResponse makeReportSetResponse() {