Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat1: 엔티티 연관관계 매핑 끝 #8

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/umc_haekathon_4/demo/domain/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public class Memory {

@OneToMany(mappedBy = "memory", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Image> images=new ArrayList<>();

@ManyToOne
@JoinColumn(name = "treasure_box_id", nullable = false)
private TeasureBox teasureBox;
}
9 changes: 5 additions & 4 deletions src/main/java/umc_haekathon_4/demo/domain/Mission.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package umc_haekathon_4.demo.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;

Expand All @@ -21,4 +18,8 @@ public class Mission {
@CreatedDate
@Column(name = "created_at")
private LocalDateTime createdDate;

@ManyToOne
@JoinColumn(name = "treasure_box_id", nullable = false)
private TeasureBox teasureBox;
}
9 changes: 9 additions & 0 deletions src/main/java/umc_haekathon_4/demo/domain/TeasureBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Entity
@Builder
Expand All @@ -13,12 +15,19 @@
public class TeasureBox {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "treasure_box_id")
private Long id;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user;

@OneToMany(mappedBy = "treasure_box", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Memory> memories=new ArrayList<>();

@OneToMany(mappedBy = "treasure_box", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Mission> missions=new ArrayList<>();

private LocalDateTime createdAt;
private LocalDateTime deadline;
private String status;
Expand Down
Loading