Skip to content

Commit

Permalink
๐ŸŽจ [Style]: Paragraph error correction(#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
hw130 authored Jul 30, 2023
1 parent ed596dd commit d2e1c02
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
### ์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ
---
- ํŒ€๊ณผ ํšŒ์›(์ผ๋Œ€๋‹ค) ๊ด€๊ณ„๋ผ๊ณ  ์ƒ๊ฐํ–ˆ์„ ๋•Œ, ํŒ€์€ ๋ชจ๋“  ํšŒ์›๋“ค์„ ์ฐธ์กฐํ•˜์ง€๋งŒ ํšŒ์›๋“ค์€ ํŒ€์„ ์ฐธ์กฐํ•˜์ง€ ์•Š์œผ๋ฉด ์ด๋ฅผ ์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ์ด๋ผ ํ•œ๋‹ค.
<img width="647" alt="แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-07-30 แ„‹แ…ฉแ„’แ…ฎ 12 04 43" src="https://github.com/luke0408/study_for_jpa_basic/assets/87763333/85ededdb-d231-4c6b-8c60-a6757094e626">
- ์œ„์™€ ๊ฐ™์€ ๊ทธ๋ฆผ์ด ๋‚˜์˜ค๊ฒŒ ๋œ๋‹ค. ์™œ๋ƒํ•˜๋ฉด ์ฐธ์กฐ๋Š” Team์ด ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋ฐ(๊ฐ์ฒด) ๋ฐ˜๋ฉด, ์ผ๋Œ€๋‹ค ๊ด€๊ณ„์—์„œ ์™ธ๋ž˜ ํ‚ค๋Š” ํ•ญ์ƒ ๋‹ค์ชฝ ํ…Œ์ด๋ธ”์— ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋”ฐ๋ผ์„œ ํฌ๋กœ์Šค ๋˜๋Š”(๋งคํ•‘ํ•œ ๊ฐ์ฒด๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ์™ธ๋ž˜ ํ‚ค๊ฐ€ ๋‹ค๋ฅธ ํ…Œ์ด๋ธ”์— ์žˆ๋Š” ๊ฒฝ์šฐ) ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•œ๋‹ค.
- ๋ณธ์ธ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์žˆ์œผ๋ฉด ์—”ํ‹ฐํ‹ฐ ์ €์žฅ๊ณผ ์—ฐ๊ด€๊ด€๊ณ„ ์ฒ˜๋ฆฌ๋ฅผ INSERT ์ฟผ๋ฆฌ ํ•œ ๋ฒˆ์œผ๋กœ ๋๋‚ผ ์ˆ˜ ์žˆ์ง€๋งŒ, ๋‹ค๋ฅธ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์žˆ์œผ๋ฉด ์—ฐ๊ด€๊ด€๊ณ„ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ UPDATE ์ฟผ๋ฆฌ๋ฅผ ์ถ”๊ฐ€๋กœ ์‹คํ–‰ํ•ด์•ผ ํ•œ๋‹ค.
- ์ฒซ ๋ฒˆ์งธ Update ์ฟผ๋ฆฌ: ์ƒˆ๋กœ์šด ๋ฉค๋ฒ„์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉค๋ฒ„ ํ…Œ์ด๋ธ”์— ์‚ฝ์ž…ํ•œ๋‹ค. ์ด ๋•Œ, ๋ฉค๋ฒ„ ํ…Œ์ด๋ธ”์˜ ์™ธ๋ž˜ ํ‚ค๋ฅผ ํ•ด๋‹น ๋ฉค๋ฒ„๊ฐ€ ์†ํ•œ ํŒ€์˜ ๊ธฐ๋ณธ ํ‚ค๋กœ ์„ค์ •ํ•œ๋‹ค. (์ฆ‰, ํŒ€๊ณผ ๋ฉค๋ฒ„ ํ…Œ์ด๋ธ”์„ ์—ฐ๊ฒฐํ•œ๋‹ค.) `INSERT INTO MemberTable (๋ฉค๋ฒ„ ์ด๋ฆ„, ํŒ€ ID) VALUES ('Tom', 1);`
- ๋‘ ๋ฒˆ์งธ Update ์ฟผ๋ฆฌ: ํŒ€ ํ…Œ์ด๋ธ”์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜์—ฌ ํ•ด๋‹น ํŒ€์˜ ๋ฉค๋ฒ„ ์ˆ˜๋ฅผ ์ฆ๊ฐ€์‹œํ‚จ๋‹ค. ์ด ๋•Œ, ํŒ€ ํ…Œ์ด๋ธ”์˜ ์™ธ๋ž˜ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฐ๊ด€๋œ ๋ฉค๋ฒ„ ์ˆ˜๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค. `UPDATE TeamTable SET ๋ฉค๋ฒ„ ์ˆ˜ = ๋ฉค๋ฒ„ ์ˆ˜ + 1 WHERE ํŒ€ ID = 1;`
<img width="647" alt="แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-07-30 แ„‹แ…ฉแ„’แ…ฎ 12 04 43" src="https://github.com/luke0408/study_for_jpa_basic/assets/87763333/85ededdb-d231-4c6b-8c60-a6757094e626">

- ์œ„์™€ ๊ฐ™์€ ๊ทธ๋ฆผ์ด ๋‚˜์˜ค๊ฒŒ ๋œ๋‹ค. ์™œ๋ƒํ•˜๋ฉด ์ฐธ์กฐ๋Š” Team์ด ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋ฐ(๊ฐ์ฒด) ๋ฐ˜๋ฉด, ์ผ๋Œ€๋‹ค ๊ด€๊ณ„์—์„œ ์™ธ๋ž˜ ํ‚ค๋Š” ํ•ญ์ƒ ๋‹ค์ชฝ ํ…Œ์ด๋ธ”์— ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋”ฐ๋ผ์„œ ํฌ๋กœ์Šค ๋˜๋Š”(๋งคํ•‘ํ•œ ๊ฐ์ฒด๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ์™ธ๋ž˜ ํ‚ค๊ฐ€ ๋‹ค๋ฅธ ํ…Œ์ด๋ธ”์— ์žˆ๋Š” ๊ฒฝ์šฐ) ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•œ๋‹ค.

- ๋ณธ์ธ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์žˆ์œผ๋ฉด ์—”ํ‹ฐํ‹ฐ ์ €์žฅ๊ณผ ์—ฐ๊ด€๊ด€๊ณ„ ์ฒ˜๋ฆฌ๋ฅผ INSERT ์ฟผ๋ฆฌ ํ•œ ๋ฒˆ์œผ๋กœ ๋๋‚ผ ์ˆ˜ ์žˆ์ง€๋งŒ, ๋‹ค๋ฅธ ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์žˆ์œผ๋ฉด ์—ฐ๊ด€๊ด€๊ณ„ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ UPDATE ์ฟผ๋ฆฌ๋ฅผ ์ถ”๊ฐ€๋กœ ์‹คํ–‰ํ•ด์•ผ ํ•œ๋‹ค.

- ์ฒซ ๋ฒˆ์งธ Update ์ฟผ๋ฆฌ: ์ƒˆ๋กœ์šด ๋ฉค๋ฒ„์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉค๋ฒ„ ํ…Œ์ด๋ธ”์— ์‚ฝ์ž…ํ•œ๋‹ค. ์ด ๋•Œ, ๋ฉค๋ฒ„ ํ…Œ์ด๋ธ”์˜ ์™ธ๋ž˜ ํ‚ค๋ฅผ ํ•ด๋‹น ๋ฉค๋ฒ„๊ฐ€ ์†ํ•œ ํŒ€์˜ ๊ธฐ๋ณธ ํ‚ค๋กœ ์„ค์ •ํ•œ๋‹ค. (์ฆ‰, ํŒ€๊ณผ ๋ฉค๋ฒ„ ํ…Œ์ด๋ธ”์„ ์—ฐ๊ฒฐํ•œ๋‹ค.) `INSERT INTO MemberTable (๋ฉค๋ฒ„ ์ด๋ฆ„, ํŒ€ ID) VALUES ('Tom', 1);`

- ๋‘ ๋ฒˆ์งธ Update ์ฟผ๋ฆฌ: ํŒ€ ํ…Œ์ด๋ธ”์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜์—ฌ ํ•ด๋‹น ํŒ€์˜ ๋ฉค๋ฒ„ ์ˆ˜๋ฅผ ์ฆ๊ฐ€์‹œํ‚จ๋‹ค. ์ด ๋•Œ, ํŒ€ ํ…Œ์ด๋ธ”์˜ ์™ธ๋ž˜ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฐ๊ด€๋œ ๋ฉค๋ฒ„ ์ˆ˜๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค. `UPDATE TeamTable SET ๋ฉค๋ฒ„ ์ˆ˜ = ๋ฉค๋ฒ„ ์ˆ˜ + 1 WHERE ํŒ€ ID = 1;`



### ์ผ๋Œ€๋‹ค ๋‹จ๋ฐฉํ–ฅ ๋‹จ์ 
Expand All @@ -32,9 +37,13 @@
### ์ผ๋Œ€๋‹ค ์–‘๋ฐฉํ–ฅ
---
<img width="556" alt="แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-07-30 แ„‹แ…ฉแ„’แ…ฎ 12 06 00" src="https://github.com/luke0408/study_for_jpa_basic/assets/87763333/d125be14-5790-44ed-b86b-02aebf7e21d8">
- `@JoinColumn(name = "TEAM_ID", insertable = false, updatable = false)` ์™€ ๊ฐ™์€ ์ฝ๊ธฐ ์ „์šฉ ํ•„๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์–‘๋ฐฉํ–ฅ ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•
- ๊ฒฐ๋ก ๋ถ€ํ„ฐ ๋งํ•˜์ž๋ฉด, ์ผ๋Œ€๋‹ค ์–‘๋ฐฉํ–ฅ์€ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค. ์‹ค์ œ๋กœ @ManyToOne ์–ด๋…ธํ…Œ์ด์…˜์—๋Š” mappedBy ์†์„ฑ์ด ์—†๋Š”๋ฐ, ์ด๋Š” ์ด ๊ด€๊ณ„์—์„œ One ์ชฝ์ด ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์ด ๋  ์ˆ˜ ์—†์Œ์„ ์‹œ์‚ฌํ•œ๋‹ค.
- ์ด์œ ๋Š” ๋‹น์—ฐํžˆ ํ•ญ์ƒ ๋‹ค ์ชฝ์— ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋”ฐ๋ผ์„œ @ManyToOne, @OneToMany ์ค‘ mappedBy๋ฅผ ์“ธ ์ˆ˜ ์žˆ๋Š” ๊ณณ์€ @OneToMany ๋ฟ์ด๋‹ค.

- `@JoinColumn(name = "TEAM_ID", insertable = false, updatable = false)` ์™€ ๊ฐ™์€ ์ฝ๊ธฐ ์ „์šฉ ํ•„๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์–‘๋ฐฉํ–ฅ ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

- ๊ฒฐ๋ก ๋ถ€ํ„ฐ ๋งํ•˜์ž๋ฉด, ์ผ๋Œ€๋‹ค ์–‘๋ฐฉํ–ฅ์€ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค. ์‹ค์ œ๋กœ @ManyToOne ์–ด๋…ธํ…Œ์ด์…˜์—๋Š” mappedBy ์†์„ฑ์ด ์—†๋Š”๋ฐ, ์ด๋Š” ์ด ๊ด€๊ณ„์—์„œ One ์ชฝ์ด ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ์ด ๋  ์ˆ˜ ์—†์Œ์„ ์‹œ์‚ฌํ•œ๋‹ค.

- ์ด์œ ๋Š” ๋‹น์—ฐํžˆ ํ•ญ์ƒ ๋‹ค ์ชฝ์— ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋”ฐ๋ผ์„œ @ManyToOne, @OneToMany ์ค‘ mappedBy๋ฅผ ์“ธ ์ˆ˜ ์žˆ๋Š” ๊ณณ์€ @OneToMany ๋ฟ์ด๋‹ค.

- ๋”ฐ๋ผ์„œ ์ผ๋Œ€๋‹ค(์ผ์ด ์—ฐ๊ด€๊ด€๊ณ„์˜ ์ฃผ์ธ) ๊ด€๊ณ„๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์€ ๋‹ค๋Œ€์ผ๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์— ๋น„ํ•ด ๋‹จ์ ์ด ๋งŽ๊ณ , ์ผ๋Œ€๋‹ค๋กœ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๋“ค์€ ๋‹น์—ฐํžˆ๋„ ๋‹ค๋Œ€์ผ๋กœ ์ „๋ถ€ ํ‘œํ˜„์ด ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค๋Œ€์ผ๋กœ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

### ๊ฒฐ๋ก  ๋ฐ ์ •๋ฆฌ
Expand Down

0 comments on commit d2e1c02

Please sign in to comment.