양방향 연관관계와 연관관계의 주인 (Bidirectional associations and masters of associations)
Bidirectional associations and masters of associations
양방향 연관관계와 연관관계의 주인 (Bidirectional associations and masters of associations)
양방향 매핑
// Member Entity
@Entity
public class Member {
@Id @GeneratedValue
@Column(name = "MEMBER_ID")
private Long id;
@Column(name = "USERNAME")
private String username;
@ManyToOne
@JoinColumn(name = "TEAM_ID")
private Team team; // mapped by 대상
}
// Team Entity
@Entity
public class Team {
@Id
@GeneratedValue
@Column(name= "TEAM_ID")
private Long id;
private String name;
@OneToMany(mappedBy = "team") // 대상
private List<Member> members = new ArrayList<>();
}객체와 테이블이 관계를 맺는 차이
연관관계의 주인(Owner)
양방향 매핑 규칙
양방향 매핑시 가장 많이 하는 실수
양방향 연관관계 주의
양방향 매핑 정리
Last updated