diff --git a/src/main/java/kusitms/server/domain/cafe/entity/Cafe.java b/src/main/java/kusitms/server/domain/cafe/entity/Cafe.java index 5e0a20d..380c4cd 100644 --- a/src/main/java/kusitms/server/domain/cafe/entity/Cafe.java +++ b/src/main/java/kusitms/server/domain/cafe/entity/Cafe.java @@ -4,6 +4,9 @@ import kusitms.server.domain.user.entity.User; import lombok.*; +import java.util.ArrayList; +import java.util.List; + @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @@ -29,4 +32,7 @@ public class Cafe { @JoinColumn(name = "user_id") private User user; + @OneToMany(mappedBy = "cafe", fetch = FetchType.LAZY) + private List cafeCompanies = new ArrayList<>(); + } diff --git a/src/main/java/kusitms/server/domain/cafe/entity/CafeCompany.java b/src/main/java/kusitms/server/domain/cafe/entity/CafeCompany.java new file mode 100644 index 0000000..3e8d78d --- /dev/null +++ b/src/main/java/kusitms/server/domain/cafe/entity/CafeCompany.java @@ -0,0 +1,28 @@ +package kusitms.server.domain.cafe.entity; + + +import jakarta.persistence.*; +import kusitms.server.domain.company.entity.Company; +import kusitms.server.domain.user.entity.User; +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Builder +@Entity +public class CafeCompany { + @Id + @Column(name = "cafe_company_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "cafe_id") + private Cafe cafe; + + @ManyToOne + @JoinColumn(name = "company_id") + private Company company; + +} diff --git a/src/main/java/kusitms/server/domain/company/entity/Company.java b/src/main/java/kusitms/server/domain/company/entity/Company.java index 96ea0b8..8c724f4 100644 --- a/src/main/java/kusitms/server/domain/company/entity/Company.java +++ b/src/main/java/kusitms/server/domain/company/entity/Company.java @@ -2,9 +2,13 @@ import jakarta.persistence.*; import kusitms.server.domain.department.entity.Department; +import kusitms.server.domain.cafe.entity.CafeCompany; import kusitms.server.domain.user.entity.User; import lombok.*; +import java.util.ArrayList; +import java.util.List; + @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @@ -27,7 +31,10 @@ public class Company { @JoinColumn(name = "user_id") private User user; - @OneToOne(mappedBy = "company", cascade = CascadeType.ALL, orphanRemoval = true) - private Department department; + @OneToMany(mappedBy = "company", cascade = CascadeType.ALL, orphanRemoval = true) + private List departments = new ArrayList<>(); + + @OneToMany(mappedBy = "company", fetch = FetchType.LAZY) + private List cafeCompanies = new ArrayList<>(); } diff --git a/src/main/java/kusitms/server/domain/department/entity/Department.java b/src/main/java/kusitms/server/domain/department/entity/Department.java index 9b20619..27670f4 100644 --- a/src/main/java/kusitms/server/domain/department/entity/Department.java +++ b/src/main/java/kusitms/server/domain/department/entity/Department.java @@ -29,7 +29,7 @@ public class Department { @JoinColumn(name = "user_id") private User user; // 유저 id - @OneToOne(fetch = LAZY, cascade = CascadeType.ALL) + @ManyToOne(fetch = LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "company_id") private Company company; // 회사 id