@Entity
public class Member {
@Id @GeneratedValue
@Column(name = "MEMBER_ID")
private Long id;
@Column(name = "USERNAME")
private String name;
@Column(name = "TEAM_ID")
private Long teamId;
//...
}
@Entity
public class Team {
@Id @GeneratedValue
@Column(name = "TEAM_ID")
private Long id;
@Column(name = "TEAMNAME")
private String name;
//...
}
//외래키 식별자를 직접 다룸.
//....
//팀저장
Team team = new Team();
team.setName("TeamA");
em.persist(team);
//회원 저장
Member member = new Member();
member.setName("member1");
member.setTeamId(team.getId());
em.persist(member);
//조회시에도 Member를 조회한다음 또 다시 Team의 아이디를 가져와 Team을 조회해야하는 번거러움이 있다.
Member findMember = em.find(Member.class, member.getId());
Long findTeamId = findMember.getTeamId();
Team findTeam = em.find(Team.class, findTeamID);
//....
연관관계가 없을때, 객체지향같지 않다. 절차지향같음.