@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@ManyToMany(mappedBy = "products")
private List<Member> members = new ArrayList<>();
}
@Entity
public class Member {
...
@ManyToMany
@JoinTable(name = "member_product")
private List<Product> products = new ArrayList<>();
...
}
@Entity
public class Member {
...
@OneToMany(mappedBy = "member")
private List<MemberProduct> memberProducts = new ArrayList<>();
...
}
@Entity
@Getter
@Setter
public class MemberProduct {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "member_id")
private Member member;
@ManyToOne
@JoinColumn(name = "product_id")
private Product product;
}
@Entity
public class Product {
...
@OneToMany(mappedBy = "product")
private List<MemberProduct> members = new ArrayList<>();
...
}
member - 매핑 테이블 - task
로 분리할 예정이다.참고
https://ict-nroo.tistory.com/127
자바 ORM 표준 JPA 프로그래밍
https://happyer16.tistory.com/entry/Spring-JPA-다대다-설정-및-주의-Many-To-Many