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

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

by rlaehddnd0422

๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋Š” ์ •๊ทœํ™”๋œ ํ…Œ์ด๋ธ” 2๊ฐœ๋กœ ๋‹ค๋Œ€๋‹ค ๊ด€๊ณ„๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. 

๊ทธ๋ž˜์„œ ํ…Œ์ด๋ธ”์—์„œ๋Š” ๋ณดํ†ต ๋‹ค๋Œ€๋‹ค ๊ด€๊ณ„๋ฅผ ์ผ๋Œ€๋‹ค + ๋‹ค๋Œ€์ผ ๊ด€๊ณ„๋กœ ํ’€์–ด๋‚ด๋Š” ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ”์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์—ฐ๊ฒฐ ํ…Œ์ด๋ธ” MEMBER_ITEM

ํ•˜์ง€๋งŒ ๊ฐ์ฒด๋Š” ํ…Œ์ด๋ธ”๊ณผ ๋‹ฌ๋ฆฌ @ManyToMany๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐ์ฒด 2๊ฐœ๋กœ ๋‹ค๋Œ€๋‹ค ๊ด€๊ณ„๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


๋‹ค๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ 

๋‹ค๋Œ€๋‹ค Member โžก๏ธ Item์„ @ManyToMany๋กœ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋งคํ•‘ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

Member

@Entity
public class Member{

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

    private String name;

    @ManyToMany
    @JoinTable(name = "MEMBER_ITEM",
            joinColumns = @JoinColumn(name = "MEMBER_ID"),
            inverseJoinColumns = @JoinColumn(name = "ITEM_ID"))
	private List<Item> items = new ArrayList<Item>();
    
    ...
}
  • Member ์—”ํ‹ฐํ‹ฐ์™€ Item ์—”ํ‹ฐํ‹ฐ๋ฅผ @ManyToMany๋กœ ๋งคํ•‘ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • @JoinTable๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ค‘๊ฐ„ ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ” ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  ๊ฐ„์ ‘์ ์œผ๋กœ  ๋งคํ•‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • @JoinTable.name : ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ” ์ด๋ฆ„ ์ง€์ •
    • @JoinTable.joinColumns : ํ˜„์žฌ ๋ฐฉํ–ฅ์ธ Member์™€ ๋งคํ•‘ํ•  ์กฐ์ธ ์ปฌ๋Ÿผ ์ •๋ณด ์ง€์ •
    • @JoinTable.inverseJoinColumns : ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์ธ Item๊ณผ ๋งคํ•‘ํ•  ์กฐ์ธ ์ปฌ๋Ÿผ ์ •๋ณด ์ง€์ •
  • MEMBER_ITEM ํ…Œ์ด๋ธ”์€ ๋‹ค๋Œ€๋‹ค ๊ด€๊ณ„๋ฅผ ์ผ๋Œ€๋‹ค-๋‹ค๋Œ€์ผ ๊ด€๊ณ„๋กœ ํ’€์–ด๋‚ด๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ”์ผ ๋ฟ์ด๊ธฐ ๋•Œ๋ฌธ์— ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ”์— ๋Œ€ํ•ด์„œ๋Š” ์‹ ๊ฒฝ์“ฐ์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค.
@Entity
public class Item{

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

    private String name;

	...
}

 

์ €์žฅ

    try
    {
        Item item = new Item();
        item.setName("์ƒํ’ˆA");
        em.persist(item);

        Item item2 = new Item();
        item2.setName("์ƒํ’ˆB");
        em.persist(item2);

        Member member = new Member();
        member.setName("ํšŒ์›A");

        member.getItems().add(item); // ์—ฐ๊ด€๊ด€๊ณ„ Member -> Item ์„ค์ •
        member.getItems().add(item2); // ์—ฐ๊ด€๊ด€๊ณ„ Member -> Item ์„ค์ •

        em.persist(member);

        for (Item memberItem : member.getItems()) {
            System.out.println("memberItem = " + memberItem.getName());
        }
        tx.commit();

    } catch (Exception e) {
        tx.rollback();
    }finally {
        em.close();
    }
    emf.close();
}

 

 

ํšŒ์›A์— ๋Œ€ํ•œ ์ƒํ’ˆA์˜ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ์„ค์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ํšŒ์›A๋ฅผ ์ €์žฅํ•  ๋•Œ ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ”์—๋„ ๊ฐ’์ด ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.

insert into item ... // itemA
insert into item ... // itemB
insert into member ... // memberA
insert into member_item ...

๋‹ค๋Œ€๋‹ค ์–‘๋ฐฉํ–ฅ

๋‹ค๋Œ€๋‹ค ์—ญ๋ฐฉํ–ฅ๋„ ๋‹ค๋Œ€๋‹ค์ด๋ฏ€๋กœ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ @ManyToMany๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์–‘์ชฝ ์ค‘ ์›ํ•˜๋Š” ๊ณณ์— mappedBy๋ฅผ ์ง€์ •ํ•ด์„œ ๋ฐ˜๋Œ€ ์ชฝ์— ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. 

 

Member

@Entity
public class Member{

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

    private String name;

    @ManyToMany
    @JoinTable(name = "MEMBER_ITEM",
                joinColumns = @JoinColumn(name="MEMBER_ID"),
                inverseJoinColumns = @JoinColumn(name="ITEM_ID"))
    private List<Item> items = new ArrayList<Item>();
    ...
}

 

Item

@Entity
public class Item{

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

    private String name;

    @ManyToMany(mappedBy = "items")	
    private List<Member> members;
}

 

// In Member Entity
public void addItem(Item item){
    items.add(item);
    item.getMembers().add(this);
}
์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„๋Š” ๋ฐ˜๋“œ์‹œ ์—ฐ๊ด€๊ด€๊ณ„ ํŽธ์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ๊ด€๋ฆฌํ•˜๋„๋ก ํ•ฉ์‹œ๋‹ค.

์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋งŒ๋“ค์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด์ œ Item์—์„œ๋„ getMembers()๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์—ญ๋ฐฉํ–ฅ ๊ฐ์ฒด ๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰์ด ๊ฐ€๋Šฅํ•ด์กŒ์Šต๋‹ˆ๋‹ค.

 

@ManyToMany๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ”์„ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ๋„๋ฉ”์ธ ๋ชจ๋ธ์ด ๋‹จ์ˆœํ•ด์ง€๊ณ  ํŽธ๋ฆฌํ•ด์ง€์ง€๋งŒ, ์‹ค๋ฌด์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ์—๋Š” ํ•œ๊ณ„๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. 

 

์˜ˆ๋ฅผ๋“ค์–ด Member ์—”ํ‹ฐํ‹ฐ์™€ Item ์—”ํ‹ฐํ‹ฐ๊ฐ€ ์žˆ์„ ๋•Œ, Member๊ฐ€ Item์„ ์ฃผ๋ฌธํ•˜๋ฉด Item Id๋งŒ ๋‹ด๊ณ  ๋๋‚ ๊ฒŒ ์•„๋‹ˆ๋ผ, ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ”์— ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰์ด๋‚˜, ์ฃผ๋ฌธ ๋‚ ์งœ, ์ฃผ๋ฌธ ๊ธˆ์•ก๊ณผ ๊ฐ™์€ ์ปฌ๋Ÿผ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

 

์ด๋Ÿฐ ๊ฒฝ์šฐ ์ง์ ‘ ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•˜๊ณ  ์—ฐ๊ฒฐ ํ…Œ์ด๋ธ”์— ์ถ”๊ฐ€ํ•  ์ปฌ๋Ÿผ๋“ค์„ ๋งคํ•‘ํ•˜๊ณ , ์ผ๋Œ€๋‹ค - ์—ฐ๊ฒฐํ…Œ์ด๋ธ” - ๋‹ค๋Œ€์ผ๋กœ ํ’€์–ด์„œ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋งคํ•‘ํ•ด์ฃผ๋Š”๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

 

์ฝ”๋“œ๋กœ ํ•œ๋ฒˆ ๋”ฐ๋ผ๊ฐ€๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


๋‹ค๋Œ€๋‹ค ๋งคํ•‘ : ์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ ์‚ฌ์šฉ

์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ง์ ‘ ๋งŒ๋“ค์–ด ๋‹ค๋Œ€๋‹ค ๋งคํ•‘์„ ํ•ด๋ด…์‹œ๋‹ค.

์—ฐ๊ฒฐ์—”ํ‹ฐํ‹ฐ ์ง์ ‘์ƒ์„ฑํ›„ ์ผ๋Œ€๋‹ค-์—ฐ๊ฒฐ์—”ํ‹ฐํ‹ฐ-๋‹ค๋Œ€์ผ๋กœ ๋งคํ•‘

Member

@Entity
public class Member {

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

    private String name;

    @OneToMany(mappedBy = "member")
    private List<MemberItem> Memberitem = new ArrayList<MemberItem>();
    
    ...
}
  • MemberItem ์ชฝ์ด ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฏ€๋กœ ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์ด ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ mappedBy ์†์„ฑ์„ ์ถ”๊ฐ€ํ•ด์ค์‹œ๋‹ค.

Item

@Entity
public class Item{

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

    private String name;


    // ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„ ๋งคํ•‘ : Item->MemberItem ์กฐํšŒ๋ฅผ ์›ํ•˜๋Š” ๊ฒฝ์šฐ
    // @OneToMany(mappedBy = "item")
    // private List<MemberItem> memberItem = new ArrayList<MemberItem>();

    ...
}
  • Item์œผ๋กœ MemberItem ์กฐํšŒ๋ฅผ ์›ํ•˜๋Š” ๊ฒฝ์šฐ ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„ ๋งคํ•‘ : MemberItem ์ชฝ์ด ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฏ€๋กœ ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์ด ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ mappedBy ์†์„ฑ์„ ์ถ”๊ฐ€ํ•ด์ค์‹œ๋‹ค.

MemberItem (์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ)

@Entity
@IdClass(MemberProductId.class)
public class MemberItem{

    @Id
    @ManyToOne
    @JoinColumns(name= "MEMBER_ID")
    private Member member;

    @Id
    @ManyToOne
    @JoinColumns(name= "ITEM_ID")
    private Item item;

    private Integer orderAmount;

    @Temporal(TemporalType.DATE)
    private Date orderDate;

    
    ...
}

๊ฐ€์žฅ ์ค‘์š”ํ•œ ์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ MemberItem์„ ์‚ดํŽด๋ด…์‹œ๋‹ค.

 

MemberItem ์—”ํ‹ฐํ‹ฐ๋ฅผ ๋ณด๋ฉด ๊ธฐ๋ณธํ‚ค๋ฅผ ๋งคํ•‘ํ•˜๋Š” @Id์™€ ์™ธ๋ž˜ํ‚ค๋ฅผ ๋งคํ•‘ํ•˜๋Š” @JoinColumns๋ฅผ ๋™์‹œ์— ์‚ฌ์šฉํ•ด์„œ member_id์™€ item_id๋ฅผ ๊ธฐ๋ณธํ‚ค + ์™ธ๋ž˜ํ‚ค๋ฅผ ํ•œ๋ฒˆ์— ๋งคํ•‘ํ•˜์˜€์Šต๋‹ˆ๋‹ค. 

๊ทธ๋ฆฌ๊ณ  @IdClass๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ณตํ•ฉ ๊ธฐ๋ณธ ํ‚ค๋ฅผ ๋งคํ•‘ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

  • MemberItem ์—”ํ‹ฐํ‹ฐ์—์„œ ๊ธฐ๋ณธํ‚ค๋Š” member_id์™€ item_id๋กœ ์ด๋ฃจ์–ด์ง„ ๋ณตํ•ฉํ‚ค์ž…๋‹ˆ๋‹ค.
  • JPA์—์„œ ๋ณตํ•ฉํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋ณ„๋„์˜ ์‹๋ณ„์ž ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. (@IdClass๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์‹๋ณ„์ž ํด๋ž˜์Šค๋ฅผ ์ง€์ •)

๋ณตํ•ฉํ‚ค ์‚ฌ์šฉ ๋ณ„๋„ ์‹๋ณ„์ž ํด๋ž˜์Šค ์ƒ์„ฑ ๋ฐฉ๋ฒ•

1. ๋ณ„๋„์˜ ์‹๋ณ„์ž ํด๋ž˜์Šค๋ฅผ ( public์œผ๋กœ ) ์ƒ์„ฑ 

2. Serializable์„ implements

3. equals, hashCode ๋ฉ”์†Œ๋“œ ๊ตฌํ˜„

4. ๊ธฐ๋ณธ ์ƒ์„ฑ์ž ์ƒ์„ฑ

public class MemberItemId implements Serializable {

    private Long member; // MemberItem.member์™€ ์—ฐ๊ฒฐ
    private Long item; // MemberItem.item๊ณผ ์—ฐ๊ฒฐ 

    public MemberItemId() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof MemberItemId)) return false;

        MemberItemId that = (MemberItemId) o;

        if (member != null ? !member.equals(that.member) : that.member != null) return false;
        return item != null ? item.equals(that.item) : that.item == null;
    }

    @Override
    public int hashCode() {
        int result = member != null ? member.hashCode() : 0;
        result = 31 * result + (item != null ? item.hashCode() : 0);
        return result;
    }
}
  • equals, hashCode ๋ฉ”์†Œ๋“œ๋Š” IDE์—์„œ ์ œ๊ณตํ•˜๋Š” ํ•„๋“œ๊ธฐ๋ฐ˜ ์ž๋™์ƒ์„ฑ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

์ €์žฅํ•˜๋Š” ์ฝ”๋“œ

    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("hello");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();

        tx.begin();

        try{
            Member member1 = new Member();
            member1.setId(1L);
            member1.setName("ํšŒ์›1");
            em.persist(member1);

            Item item1 = new Item();
            item1.setId(1L);
            item1.setName("์ƒํ’ˆ1");
            em.persist(item1);

            MemberItem memberItem = new MemberItem();
            memberItem.setMember(member1); // MemberItem -> member1
            memberItem.setItem(item1);
            memberItem.setOrderAmount(2);
            memberItem.setOrderDate(new Date());

            em.persist(memberItem);

            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }finally {
            em.close();
        }

        emf.close();
    }
    
}

์ฝ”๋“œ ์‹คํ–‰ ํ›„ ์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ MEMBERITEM ์กฐํšŒ

 

 MemberItem ์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ์—์„œ item_id์™€ member_id๋ฅผ ๋ณตํ•ฉํ‚ค๋กœ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. 

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


๋‹ค๋Œ€๋‹ค ์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ - ๋Œ€๋ฆฌํ‚ค ๋„์ž… 

Member_Item ์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ์— ๊ณ ์œ ์˜ ๋Œ€๋ฆฌํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋งคํ•‘ํ•ด๋ด…์‹œ๋‹ค.

๊ธฐ์กด Member, Item ์—”ํ‹ฐํ‹ฐ๋Š” ๋ณ€๊ฒฝ์‚ฌํ•ญ X
@Entity
public class MemberItem {

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

    @ManyToOne
    @JoinColumn(name = "MEMBER_ID")
    private Member member;

    @ManyToOne
    @JoinColumn(name = "ITEM_ID")
    private Item item;

    private Integer orderAmount;

    @Temporal(TemporalType.DATE)
    private Date orderDate;

	...
}

 

์ด ์ „์— ๋ฐ›์•„์˜จ ์‹๋ณ„์ž๋ฅผ ๊ธฐ๋ณธํ‚ค+์™ธ๋ž˜ํ‚ค๋กœ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‹๋ณ„๊ด€๊ณ„๋ผ๊ณ  ํ•˜๊ณ , ๋ฐ›์•„์˜จ ์‹๋ณ„์ž๋Š” ์™ธ๋ž˜ํ‚ค๋กœ๋งŒ ์‚ฌ์šฉํ•˜๊ณ  ์ƒˆ๋กœ์šด ์‹๋ณ„์ž๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์„ ๋น„ ์‹๋ณ„๊ด€๊ณ„๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

 

๋น„์‹๋ณ„๊ด€๊ณ„๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์‹๋ณ„์ž ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์ง€ ์•Š๊ณ  ๋‹จ์ˆœํ•˜๊ฒŒ ORM ๋งคํ•‘์„ ํ•  ์ˆ˜ ์žˆ์„ ๋ฟ๋”๋Ÿฌ ๋น„์ฆˆ๋‹ˆ์Šค ํ‚ค์— ์˜์กดํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์žฅ์ ๋•Œ๋ฌธ์— ์‹ค๋ฌด์—์„œ๋Š” ๋‹ค๋Œ€๋‹ค ๋งคํ•‘์—์„œ ๋น„์‹๋ณ„๊ด€๊ณ„๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ „๋žต์„ ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค.


<์ •๋ฆฌ>

  • ๋‹ค๋Œ€๋‹ค ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ์ค‘๊ฐ„ ์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ ์ƒ์„ฑ์—†์ด 2๊ฐœ์˜ ๊ฐ์ฒด๋งŒ์œผ๋กœ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋งคํ•‘ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.
    • ์ถ”๊ฐ€์ ์ธ ์ปฌ๋Ÿผ์ด ํ•„์š”ํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค๋Š” ํ•œ๊ณ„๊ฐ€ ์žˆ์–ด, ์‹ค๋ฌด์—์„œ๋Š” ์ด๋Ÿฐ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ๋‹ค๋Œ€๋‹ค ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ์ผ๋Œ€๋‹ค, ๋‹ค๋Œ€์ผ๋กœ ํ’€์–ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.
    • ์ถ”๊ฐ€์ ์ธ ์ปฌ๋Ÿผ์„ ์ถ”๊ฐ€ํ•˜๊ณ , ์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•˜๊ณ , ์‹๋ณ„๊ด€๊ณ„๋ฅผ ์‚ฌ์šฉํ•ด ์‹๋ณ„์ž๋ฅผ ๊ธฐ๋ณธํ‚ค + ์™ธ๋ž˜ํ‚ค๋กœ ์‚ฌ์šฉํ•ด ๋‹ค๋Œ€๋‹ค ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋งคํ•‘ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. / ์‹๋ณ„์ž ํด๋ž˜์Šค๋ฅผ ๋ณ„๋„๋กœ ์ƒ์„ฑํ•ด์ฃผ์–ด์•ผ ํ•˜๋Š” ๋ถˆํŽธํ•จ, ๋น„์ฆˆ๋‹ˆ์Šค ํ‚ค๋ฅผ ๋ณตํ•ฉํ‚ค๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์— ๋Œ€ํ•œ ์ฐ์ฐํ•จ์ด ๋‚จ์Œ.
    • ์ถ”๊ฐ€์ ์ธ ์ปฌ๋Ÿผ์„ ์ถ”๊ฐ€ํ•˜๊ณ , ์—ฐ๊ฒฐ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•˜๊ณ , ๋น„ ์‹๋ณ„๊ด€๊ณ„๋ฅผ ์‚ฌ์šฉํ•ด ๋Œ€๋ฆฌํ‚ค๋กœ ๋‹ค๋Œ€๋‹ค ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋งคํ•‘ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. / ๋ณตํ•ฉํ‚ค๋ฅผ ์œ„ํ•œ ์‹๋ณ„์ž ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค ํ•„์š”๊ฐ€ ์—†๊ณ , ๋น„์ฆˆ๋‹ˆ์Šคํ‚ค์— ์˜์กดํ•˜์ง€ ์•Š์•„ ์‹ค๋ฌด์—์„œ ์ž์ฃผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

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

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

Study Repository

rlaehddnd0422

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