# 일대다\[1:N]

**일**대다 : **일 테이블(엔티티)** 가 연관관계의 주인이다

Team을 연관관계 주인으로 두고, 외래키인 \<Member> 컬렉션을 관리한다고 해보자.\
Team이 \<Member>컬렉션(FK)을 관리한다면 수정할 때 MEMBER 테이블이 업데이트된다.\
\=>TEAM만 업데이트하는 게 아니라 MEMBER 테이블도 업데이트!\
실제 현업에서는 수십개의 테이블이 존재하는데 이렇게 중복되는 업데이트가 있다면 성능이 저하된다. 그러므로 **일(주인)**&#xB300;다로 하지말고 **다(주인)**&#xB300;일로 설계를 하자!

![일대다(Team이 주인)](blob:https://app.gitbook.com/19fdadb2-0356-45d5-aafa-fb559d293188)

* 일대다 : **일(1) 쪽이 연관관계의 주인**=> **FK 수정**하면 **주인과 주인반대편 모두 수정이 일어남.**\
  테이블 일대다 관계는 항상 다 쪽에 FK가 있다!
* 객체와 테이블의 차이 때문에 반대편 테이블의 외래 키를 관리하는 특이한 구조\
  \=>**연관관계 관리**를 위해 추가로 UPDATE SQL 실행된다!
* @JoinColumn을 꼭 사용해야 함=>그렇지 않으면 @JoinTable 을 사용\
  \=> 중간에 테이블을 하나 추가하는데 이는 성능상 운영하는데에 영향을 준다.

일대다 양방향 정리(실무에서 필요에 의해 간간히 사용된다고 함.)

* 주인 반대편 : **@JoinColumn(insertable=false, updatable=false)**

  @JoinColumn(name = "TEMA\_ID")으로만 하면 Hibernate는 연관관계 주인이 2개이기 때문에 에러가 발생하거나 에러없이 동작하더라도 잘못된 결과를 도출해낸다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heunnajo.gitbook.io/jpa-basic/6./1-n.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
