diff --git a/src/main/java/com/m9d/sroom/common/entity/jpa/SummaryEntity.java b/src/main/java/com/m9d/sroom/common/entity/jpa/SummaryEntity.java index 2949faf1..e54b1559 100644 --- a/src/main/java/com/m9d/sroom/common/entity/jpa/SummaryEntity.java +++ b/src/main/java/com/m9d/sroom/common/entity/jpa/SummaryEntity.java @@ -20,7 +20,7 @@ public class SummaryEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long summaryId; - @OneToOne + @ManyToOne @JoinColumn(name = "video_id") private VideoEntity video; diff --git a/src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java b/src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java index 116ce81b..5cb65b30 100644 --- a/src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java +++ b/src/main/java/com/m9d/sroom/common/entity/jpa/VideoEntity.java @@ -12,6 +12,7 @@ import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; +import java.util.Objects; @Entity @Table(name = "VIDEO") @@ -43,9 +44,10 @@ public class VideoEntity { @Embedded private Review review; - @OneToOne - @JoinColumn(name = "summary_id") - private SummaryEntity summary; + @OneToMany(mappedBy = "video") + private List summaries = new ArrayList(); + + private Long summaryId; private Integer materialStatus; @@ -75,7 +77,16 @@ public static VideoEntity create(Video video) { video.getMembership()); } + public SummaryEntity getSummary() { + return summaries.stream() + .filter(summary -> !summary.isModified()) + .filter(summary -> Objects.equals(summary.getSummaryId(), summaryId)) + .findFirst() + .orElse(null); + } + public void setSummary(SummaryEntity summary) { - this.summary = summary; + this.getSummaries().add(summary); + this.summaryId = summary.getSummaryId(); } }