작성
·
236
0
@Entity
public class Team {
@Id
@GeneratedValue
@Column(name="TEAM_ID")
private Long id;
@Column(name="TEAM_NAME")
private String teamName;
@Column(name="TEAM_CODE")
private String teamCode;
@OneToMany(mappedBy = "team") // 읽기 전용
private List<Member> members = new ArrayList<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public String getTeamCode() {
return teamCode;
}
public void setTeamCode(String teamCode) {
this.teamCode = teamCode;
}
public List<Member> getMembers() {
return members;
}
public void setMembers(List<Member> members) {
this.members = members;
}
}
@Entity
public class Member {
@Id
@GeneratedValue
@Column(name="MEMBER_ID")
private Long id;
@Column(name= "MEMBER_NAME")
private String memberName;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TEAM_CODE", referencedColumnName = "TEAM_CODE") // DEL_YN = 'N' 추가하려면?
private Team team;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getMemberName() {
return memberName;
}
public void setMemberName(String memberName) {
this.memberName = memberName;
}
public Team getTeam() {
return team;
}
public void changeTeam(Team team) {
this.team = team;
team.getMembers().add(this);
}
}
답변 1
2
안녕하세요. 함장수님, 공식 서포터즈 David입니다.
@Where을 사용하시면 됩니다. 아래 글을 참고해주세요:)
https://cheese10yun.github.io/jpa-where/
감사합니다.
답변 감사합니다.
많은 도움이 되었습니다.