# [JPA] ๋‹ค๋Œ€์ผ, ์ผ๋Œ€๋‹ค, ์ผ๋Œ€์ผ (๋‹จ๋ฐฉํ–ฅ, ์–‘๋ฐฉํ–ฅ) ์—ฐ๊ด€๊ด€๊ณ„ ๋งคํ•‘
Study Repository

[JPA] ๋‹ค๋Œ€์ผ, ์ผ๋Œ€๋‹ค, ์ผ๋Œ€์ผ (๋‹จ๋ฐฉํ–ฅ, ์–‘๋ฐฉํ–ฅ) ์—ฐ๊ด€๊ด€๊ณ„ ๋งคํ•‘

by rlaehddnd0422

๋‹ค์ค‘์„ฑ๊ณผ ๋‹จ๋ฐฉํ–ฅ, ์–‘๋ฐฉํ–ฅ์„ ๊ณ ๋ คํ•œ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ํ•˜๋‚˜์”ฉ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. (์™ผ์ชฝ์ด ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ)


๋‹ค๋Œ€์ผ(N:1) 

๋‹ค๋Œ€์ผ ๊ด€๊ณ„ ํŠน์ง•

  • ๋‹ค๋Œ€์ผ ๊ด€๊ณ„์˜ ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์€ ํ•ญ์ƒ ์ผ๋Œ€๋‹ค ๊ด€๊ณ„์ž…๋‹ˆ๋‹ค.
  • ์ผ๋Œ€๋‹ค ๊ด€๊ณ„์˜ ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์€ ํ•ญ์ƒ ๋‹ค๋Œ€์ผ ๊ด€๊ณ„์ž…๋‹ˆ๋‹ค.
  • ํ…Œ์ด๋ธ”์˜ ๋‹ค๋Œ€์ผ, ์ผ๋Œ€๋‹ค ๊ด€๊ณ„์—์„œ ์™ธ๋ž˜ํ‚ค๋Š” ํ•ญ์ƒ ๋‹ค ์ชฝ์— ์žˆ์Šต๋‹ˆ๋‹ค. 

๋‹ค๋Œ€์ผ ๋‹จ๋ฐฉํ–ฅ ์–‘๋ฐฉํ–ฅ ๋งคํ•‘์€ ์ด ์ „ ํฌ์ŠคํŒ…์—์„œ ๋‹ค๋ฃจ์—ˆ์ง€๋งŒ, ๋‹ค์‹œ ํ•œ ๋ฒˆ ๋‹ค๋ฃจ๊ฒ ์Šต๋‹ˆ๋‹ค.

 

[JPA] ์—ฐ๊ด€๊ด€๊ณ„ ๋งคํ•‘ - ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„

๋ฐ”๋กœ ์ด์ „ ํฌ์ŠคํŒ…์—์„œ ๋‹จ๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค. ๋‹จ๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๊ฐ„๋‹จํžˆ ์งš๊ณ  ๋„˜์–ด๊ฐ€์ž๋ฉด, Member โ–ถ๏ธŽ Team์˜ ๋‹จ๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๊ฐ€์งˆ ๋•Œ Member ์—”ํ‹ฐํ‹ฐ์—์„œ๋Š” Team ์—”ํ‹ฐํ‹ฐ๋ฅผ ์•Œ ์ˆ˜

rlaehddnd0422.tistory.com


๋‹ค๋Œ€์ผ ๋‹จ๋ฐฉํ–ฅ  N โžก๏ธ 1

Member (N) โžก๏ธ Team (1) 

Member Entity

@Entity
public class Member{
    
    @Id @GeneratedValue
    @Column(name = "MEMBER_ID")
    private Long id;

    private String name;

    @ManyToOne
    @JoinColumn(name = "TEAM_ID")
    private Team team;

}
  • @JoinColumn์œผ๋กœ ์ฐธ์กฐํ•  ์™ธ๋ž˜ ํ‚ค์™€ ๋งคํ•‘, ์ฆ‰ Member๊ฐ€ ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์ด๋ฉฐ ํšŒ์› ํ…Œ์ด๋ธ”์˜ TEAM_ID ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

Team Entity

@Entity
public class Team{
    
    @Id @GeneratedValue
    @Column(name = "TEAM_ID")
    private Long id;

    private String name;
}
  • ๋‹จ๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„์ด๋ฏ€๋กœ @OneToMany ์‚ฌ์šฉํ•˜์—ฌ members ํ•„๋“œ๋ฅผ ์„ค์ •ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

ํšŒ์›์€ Member.team์œผ๋กœ ํŒ€ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ๋ฐ˜๋Œ€๋กœ ํŒ€์—๋Š” ํšŒ์›์„ ์ฐธ์กฐํ•˜๋Š” ํ•„๋“œ๊ฐ€ ์—†๋Š” ๋‹จ๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„์ž…๋‹ˆ๋‹ค.


๋‹ค๋Œ€์ผ ์–‘๋ฐฉํ–ฅ N ↔๏ธ 1

Member (N) ↔๏ธ Team (1) ์–‘๋ฐฉํ–ฅ ๋งคํ•‘์—์„œ๋Š” ํ•ญ์ƒ "๋‹ค" ์ชฝ์ด ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์ด ๋ฉ๋‹ˆ๋‹ค.

Member Entity

@Entity
public class Member{
    
    @Id @GeneratedValue
    @Column(name = "MEMBER_ID")
    private Long id;

    private String name;

    @ManyToOne
    @JoinColumn(name = "TEAM_ID")
    private Team team;

}
  • ๋ณ€๊ฒฝ์  X

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<Member>();
    
    public void addMember(Member member){
    	this.members.add(member);
        if(member.getTeam() != this){
        	member.setTeam(this);
        }
}
  • @OneToMany๋กœ ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„ ๋งคํ•‘ + mappedBy ์†์„ฑ ์ถ”๊ฐ€
  • ํŽธ์˜๋ฉ”์†Œ๋“œ addMember(member) ๋กœ ์–‘๋ฐฉํ–ฅ ์ž๋™ ๋งคํ•‘ ์„ค์ •

์ผ๋Œ€๋‹ค(1:N)

์ผ๋Œ€๋‹ค ๊ด€๊ณ„๋Š” ๋‹ค๋Œ€์ผ ๊ด€๊ณ„์˜ ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์ž…๋‹ˆ๋‹ค. ์ผ๋Œ€๋‹ค ๊ด€๊ณ„๋Š” ์—”ํ‹ฐํ‹ฐ๋ฅผ ํ•˜๋‚˜ ์ด์ƒ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ž๋ฐ” ์ปฌ๋ ‰์…˜์ธ Collection, List, Set, Map์ค‘์— ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.


์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ 1 โžก๏ธ N  

๋ณดํ†ต์€ ์ž์‹ ์ด ๋งคํ•‘ํ•œ ํ…Œ์ด๋ธ”์˜ ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ด€๋ฆฌํ•˜์ง€๋งŒ,  ์ผ๋Œ€๋‹ค ๊ด€๊ณ„์—์„œ "์ผ"์ด ์™ธ๋ž˜ํ‚ค ๊ด€๋ฆฌ์ž, ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์ด ๋˜๋ ค๋ฉด ์™ธ๋ž˜ํ‚ค๋Š” ํ•ญ์ƒ "๋‹ค" ์ชฝ์— ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ฐธ์กฐ ํ•„๋“œ๊ฐ€ ์žˆ๋Š” "๋‹ค" ํ…Œ์ด๋ธ”๊ณผ ๋งคํ•‘์„ ํ•ด์ฃผ์–ด์•ผ ํ•˜๋Š” ํŠน์ดํ•œ ๋ชจ์Šต์ด ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.

  

Team Entity

@Entity
public class Team{
	
    @Id @GeneratedValue
    @Column(name = "TEAM_ID")
    private Long id;

    private String name;

    @OneToMany
    @JoinColumn(name = "TEAM_ID") // MEMBER ํ…Œ์ด๋ธ”์˜ TEAM_ID (FK)
    private List<Member> members = new ArrayList<Member>();

 

Member Entity

@Entity
public class Member{
    
    @Id @GeneratedValue
    @Column(name = "MEMBER_ID")
    private Long id;

    private String name;
	
}

์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ ๊ด€๊ณ„๋ฅผ ๋งคํ•‘ํ•  ๋•Œ๋Š” @JoinColumn์„ ๋ฐ˜๋“œ์‹œ ๋ช…์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด, JPA๋Š” ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ”์„ ์ค‘๊ฐ„์— ๋‘๊ณ  ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ์กฐ์ธ ํ…Œ์ด๋ธ” ์ „๋žต์„ ๊ธฐ๋ณธ์œผ๋กœ ์‚ฌ์šฉํ•ด์„œ ๋งคํ•‘ํ•ฉ๋‹ˆ๋‹ค.

 

์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ ๋งคํ•‘์˜ ๋‹จ์ 

  • ๋งคํ•‘ํ•œ ๊ฐ์ฒด๊ณผ ๊ด€๋ฆฌํ•˜๋Š” ์™ธ๋ž˜ ํ‚ค๊ฐ€ ๋‹ค๋ฅธํ…Œ์ด๋ธ”์— ์žˆ์–ด ์—ฐ๊ด€๊ด€๊ณ„ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ UPDATE SQL์„ ์ถ”๊ฐ€์ ์œผ๋กœ ์‹คํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • Team ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ €์žฅํ•  ๋•Œ Team.members์˜ ์ฐธ์กฐ ๊ฐ’์„ ํ™•์ธํ•ด์„œ ํšŒ์› ํ…Œ์ด๋ธ”์— ์žˆ๋Š” TEAM_ID ์™ธ๋ž˜ ํ‚ค๋ฅผ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.
  • ํ‚ค ๊ด€๋ฆฌ๊ฐ€ ๋ณต์žกํ•˜๊ณ  ๋‹จ์ˆœํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ ๋งคํ•‘๋ณด๋‹ค๋Š” ๋‹ค๋Œ€์ผ ์–‘๋ฐฉํ–ฅ ๋งคํ•‘์„ ์‚ฌ์šฉํ•ฉ์‹œ๋‹ค.

์ผ๋Œ€๋‹ค ์–‘๋ฐฉํ–ฅ ๋งคํ•‘ 

์–‘๋ฐฉํ–ฅ ๋งคํ•‘์—์„œ @OneToMany๋Š” ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์ด ๋  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์—, ์ผ๋Œ€๋‹ค ์–‘๋ฐฉํ–ฅ ๋งคํ•‘์€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 


์ผ๋Œ€์ผ(1:1)

์ผ๋Œ€์ผ ๊ด€๊ณ„๋Š” ์–‘์ชฝ์ด ์„œ๋กœ ํ•˜๋‚˜์˜ ๊ด€๊ณ„๋งŒ ๊ฐ€์ง‘๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ํšŒ์›์€ ํ•˜๋‚˜์˜ ์‚ฌ๋ฌผํ•จ๋งŒ ์‚ฌ์šฉํ•˜๊ณ  ์‚ฌ๋ฌผํ•จ๋„ ํ•˜๋‚˜์˜ ํšŒ์›์— ์˜ํ•ด์„œ๋งŒ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

ํŠน์ง•

  • ์ผ๋Œ€์ผ ๊ด€๊ณ„์˜ ๋ฐ˜๋Œ€๋„ ์ผ๋Œ€์ผ ๊ด€๊ณ„.
  • ํ…Œ์ด๋ธ” ๊ด€๊ณ„์—์„œ ์ผ๋Œ€๋‹ค, ๋‹ค๋Œ€์ผ์€ ํ•ญ์ƒ ๋‹ค์ชฝ์ด ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ผ๋Œ€์ผ ๊ด€๊ณ„์—์„œ๋Š” ์ฃผ ํ…Œ์ด๋ธ”์ด๋‚˜ ๋Œ€์ƒ ํ…Œ์ด๋ธ” ๋‘˜ ์ค‘ ์–ด๋Š๊ณณ์—์„œ๋‚˜ ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฃผ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ํ‚ค ์„ค์ •

:  ์ฃผ ๊ฐ์ฒด๊ฐ€ ๋Œ€์ƒ ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์ฃผ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ํ‚ค๋ฅผ ๋‘๊ณ  ๋Œ€์ƒ ํ…Œ์ด๋ธ”์„ ์ฐธ์กฐํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

์ผ๋ฐ˜์ ์œผ๋กœ ์ด ๋ฐฉ์‹์„ ์ฑ„ํƒํ•ฉ๋‹ˆ๋‹ค. JPA๋„ ์ฃผ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์žˆ์œผ๋ฉด ์ข€ ๋” ํŽธ๋ฆฌํ•˜๊ฒŒ ๋งคํ•‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • Member - ์ฃผ ํ…Œ์ด๋ธ”
  • Locker - ๋Œ€์ƒ ํ…Œ์ด๋ธ”

๋‹จ๋ฐฉํ–ฅ 

์ผ๋Œ€์ผ ๊ด€๊ณ„์ด๋ฏ€๋กœ ๊ฐ์ฒด ๋งคํ•‘์— @OneToOne์„ ์‚ฌ์šฉํ•ด ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋งคํ•‘ํ•ด์ค๋‹ˆ๋‹ค.

@Entity
public class Member{

    @Id @GeneratedValue
    @Column(name="MEMBER_ID")
    private Long id;

    private String username;

    @OneToOne
    @JoinColumn(name = "LOCKER_ID")
    private Locker locker;

}

@Entity
public class Locker{

    @Id @GeneratedValue
    @Column(name="LOCKER_ID")
    private Long id;

    private String name;
}

์–‘๋ฐฉํ–ฅ

๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์—๋„ ์ถ”๊ฐ€์ ์œผ๋กœ @OneToOne์„ ์„ค์ •ํ•ด์ค๋‹ˆ๋‹ค. ๋‹จ, ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„์˜ ๋Œ€์ƒ์ด ๋˜๋Š” ํ…Œ์ด๋ธ”์ด๋ฏ€๋กœ ๋‹ค๋Œ€์ผ ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„ ๋งคํ•‘๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ mappedBy ์†์„ฑ์„ ์ถ”๊ฐ€ํ•ด์ฃผ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.

// ์ฃผ ๊ฐ์ฒด
@Entity
public class Member{

    @Id @GeneratedValue
    @Column(name="MEMBER_ID")
    private Long id;

    private String username;

    @OneToOne
    @JoinColumn(name = "LOCKER_ID")
    private Locker locker;

}


// ๋Œ€์ƒ ๊ฐ์ฒด
@Entity
public class Locker{

    @Id @GeneratedValue
    @Column(name="LOCKER_ID")
    private Long id;

    private String name;
    
    @OneToOne(mappedBy = "locker")
    private Member member; 
}

๋Œ€์ƒ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ํ‚ค ์„ค์ •

์ด๋ฒˆ์—๋Š” ๋Œ€์ƒ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์žˆ๋Š” ์ผ๋Œ€์ผ ๊ด€๊ณ„๋ฅผ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

๋‹จ๋ฐฉํ–ฅ 

JPA์—์„œ ์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ ๊ด€๊ณ„์€ ๋Œ€์ƒ ํ…Œ์ด๋ธ”๋กœ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋งคํ•‘์„ ์ง€์›ํ•˜์ง€๋งŒ, ๋Œ€์ƒ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ํ‚ค๊ฐ€ ์žˆ๋Š” ์ผ๋Œ€์ผ ๋‹จ๋ฐฉํ–ฅ ๊ด€๊ณ„๋Š” ๋งคํ•‘์„ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์ด ๋•Œ๋Š” ๋‹จ๋ฐฉํ–ฅ ๊ด€๊ณ„๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด Locker โžก๏ธ Member๋กœ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜, ์–‘๋ฐฉํ–ฅ ๊ด€๊ณ„๋กœ ๋งŒ๋“ค๊ณ  Locker๋ฅผ ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์œผ๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

 Locker โžก๏ธ Member๋กœ ์ˆ˜์ •

// ์ฃผ ๊ฐ์ฒด
@Entity
public class Locker{

    @Id @GeneratedValue
    @Column(name="LOCKER_ID")
    private Long id;

    private String name;
    
    @OneToOne
    private Member member; 
}


// ๋Œ€์ƒ ๊ฐ์ฒด
@Entity
public class Member{

    @Id @GeneratedValue
    @Column(name="MEMBER_ID")
    private Long id;

    private String username;

    @OneToOne(mappedBy = "member")
    @JoinColumn(name = "LOCKER_ID")
    private Locker locker;
}

 

์–‘๋ฐฉํ–ฅ ๊ด€๊ณ„๋กœ ์ˆ˜์ •

@Entity
public class Member{

    @Id @GeneratedValue
    @Column(name="MEMBER_ID")
    private Long id;

    private String username;

    @OneToOne
    @JoinColumn(name = "LOCKER_ID")
    private Locker locker;

}

@Entity
public class Locker{

    @Id @GeneratedValue
    @Column(name="LOCKER_ID")
    private Long id;

    private String name;
    
    @OneToOne(mappedBy = "locker")
    private Member member;
}

์–‘๋ฐฉํ–ฅ

๋Œ€์ƒ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ํ‚ค๊ฐ€ ์žˆ๋Š” ์–‘๋ฐฉํ–ฅ ๊ด€๊ณ„๋ฅผ ์•Œ์•„๋ด…์‹œ๋‹ค.

// ์ฃผ ๊ฐ์ฒด
@Entity
public class Member{

    @Id @GeneratedValue
    @Column(name="MEMBER_ID")
    private Long id;

    private String username;

    @OneToOne(mappedBy = "member")
    private Locker locker;

}


// ๋Œ€์ƒ ๊ฐ์ฒด
@Entity
public class Locker{

    @Id @GeneratedValue
    @Column(name="LOCKER_ID")
    private Long id;

    private String name;
    
    @OneToOne
    @JoinColumn(name = "MEMBER_ID")
    private Member member; 
}
  • ์ผ๋Œ€์ผ ๋งคํ•‘์—์„œ ๋Œ€์ƒ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ํ‚ค๋ฅผ ๋‘๊ณ  ์‹ถ์œผ๋ฉด ์–‘๋ฐฉํ–ฅ์œผ๋กœ ๋งคํ•‘ํ•˜๊ณ , ๋Œ€์ƒ ์—”ํ‹ฐํ‹ฐ์ธ Locker๋ฅผ ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์œผ๋กœ ๋งŒ๋“ค์–ด์„œ Locker ํ…Œ์ด๋ธ”์˜ ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ด€๋ฆฌํ•˜๋„๋ก ์„ค์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

<์ •๋ฆฌ>

  • ๋‹ค๋Œ€์ผ, ์ผ๋Œ€๋‹ค, ์ผ๋Œ€์ผ ๋‹จ๋ฐฉํ–ฅ ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค.
  • ์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ ๊ด€๊ณ„๋ฅผ ๋งคํ•‘ํ•  ๋•Œ๋Š” @JoinColumn์„ ๋ฐ˜๋“œ์‹œ ๋ช…์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์ผ๋Œ€์ผ ๋งคํ•‘์—์„œ ์™ธ๋ž˜ํ‚ค๋Š” ์ฃผ ํ…Œ์ด๋ธ”์—๋„ ๋Œ€์ƒ ํ…Œ์ด๋ธ”์—์„œ๋„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • JPA๋Š” ์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ ๋งคํ•‘์€ ์ง€์›ํ•˜์ง€๋งŒ, ์ผ๋Œ€์ผ ๋‹จ๋ฐฉํ–ฅ ๋งคํ•‘์€ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

<์ฐธ๊ณ ์ž๋ฃŒ>

 

 

๋ธ”๋กœ๊ทธ์˜ ์ •๋ณด

Study Repository

rlaehddnd0422

ํ™œ๋™ํ•˜๊ธฐ