-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- JPAμ μν°ν° 맀λμ μ μμμ± μ»¨ν μ€νΈ
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Entity Manager | ||
|
||
## Entity Manager | ||
|
||
- JPA κΈ°λ₯μ μ 곡νλ κ°μ²΄ | ||
- λ΄λΆμ DataSource(Database Connection)λ₯Ό μμ | ||
- μ ν리μΌμ΄μ λ 벨μ κ°μ λ°μ΄ν°λ² μ΄μ€λ‘ λ³Ό μ μμ | ||
- Thread-safeνμ§ **μμ**. μ¬λ¬ μ€λ λκ° νλμ Entity Manager κ°μ²΄λ₯Ό 곡μ νλ©΄ μ λ¨ | ||
- EntityManagerμ λ¬λ¦¬ EntityManagerFactoryλ μμ± λΉμ©μ΄ ν° κ°μ²΄λ‘ μ ν리μΌμ΄μ μ 체μμ λ¨ ν λ²λ§ μμ±νκ³ κ³΅μ ν΄μ μ¬μ©ν΄μΌ ν¨ (Singleton) | ||
|
||
## Persistence Context (μμμ± μ»¨ν μ€νΈ) | ||
|
||
- μν°ν° 맀λμ κ° λ΄λΆμ μΌλ‘ κ΄λ¦¬νλ μν°ν° μν 보κ΄μ | ||
- μν°ν° λν κ°μ²΄μ΄κ³ , κΈ°λ₯μ΄ μνλλ©° λ΄λΆ κ°μ΄ λ³κ²½λ¨ | ||
- μμμ± μ»¨ν μ€νΈλ μν°ν°μ μ΅μ΄ λ±λ‘ μμ μ μνλ₯Ό **μ€λ μ·**μΌλ‘ μ μ₯νκ³ , λ°μ΄ν°λ² μ΄μ€μ λ°μνλ μμ κ³Ό μ€λ μ·μ λΉκ΅ν΄ 쿼리λ₯Ό μ€νν¨ | ||
|
||
### μν°ν° μλͺ μ£ΌκΈ° | ||
|
||
- μμμ± μ»¨ν μ€νΈλ₯Ό κΈ°μ€μΌλ‘ μν°ν°λ 4κ°μ§ μνλ₯Ό κ°μ§ μ μμ | ||
1. λΉμμ(new/transient) - μμ§ μμμ± μ»¨ν μ€νΈμ μ μ₯λ μ μμ | ||
2. μμ(managed) - μμμ± μ»¨ν μ€νΈμ μ μ₯λμ΄ μμ | ||
3. μ€μμ(detached) - μμμ± μ»¨ν μ€νΈμ μ μ₯λμλ€κ° λΆλ¦¬λ¨ | ||
4. μμ (removed) - μν°ν°κ° μμ λ¨ | ||
- μλ³μκ° μλ€λ©΄ λΉμμ μνλ‘ λ³Ό μ μκ³ , μλ³μκ° μλ€λ©΄ μμμ± μ»¨ν μ€νΈμ κ΄λ¦¬λ₯Ό λ°λμ§ μ¬λΆμ λ°λΌ μμκ³Ό μ€μμμΌλ‘ λλ¨. μμ μνλ DBμ λ°μλ λ delete μΏΌλ¦¬κ° μ€νλλ μνλ₯Ό λ§ν¨ | ||
|
||
### μμμ± μ»¨ν μ€νΈκ° μ§μνλ κΈ°λ₯ | ||
|
||
1. **1μ°¨ μΊμ** | ||
- μμμ± μ»¨ν μ€νΈλ μΊμμ μν μ ν¨. νΉμ μν°ν°λ₯Ό μ‘°ννλ €κ³ ν λ 1μ°¨ μΊμμ ν΄λΉ μν°ν°κ° μλ€λ©΄ DBλ₯Ό μ‘°ννμ§ μκ³ ν΄λΉ μν°ν°λ₯Ό λ°νν¨ | ||
- μΊμ ν€λ μλ³μ, μΊμ κ°μ μν°ν° κ·Έ μ체 | ||
2. **λμΌμ± 보μ₯** | ||
- μμμ± μ»¨ν μ€νΈμμλ κ°μ μλ³μλ₯Ό κ°μ§ μν°ν°λ₯Ό μ‘°ννλ©΄ νμ κ°μ κ°μ²΄λ₯Ό λ°νν¨ | ||
3. **μ°κΈ° μ§μ°** | ||
- νΈλμμ μ μμμ±μ κΈ°λ°ν κΈ°λ₯μΌλ‘, λͺ¨λ μ°κΈ°(insert/update/delete) 쿼리λ€μ νΈλμμ μ μ»€λ° μμ μ μνλλλ‘ ν¨ | ||
- μμμ± μ»¨ν μ€νΈμ λ΄κΈ°λ λ³κ²½λ€μ΄ νΈλμμ λ²μ μμμ μ΄λ£¨μ΄μ§κΈ° λλ¬Έμ, μ λΆ λ°μνκ±°λ λ‘€λ°±νκ±°λ λ μ€ νλμ΄κΈ° λλ¬Έμ ν¨μ¨μ±μ μν΄ μ»€λ° μμ μ ν λ²μ λ°μνλ κ² | ||
- μ μν μ - commit == μ°κΈ° μ§μ° μνμ΄ μλ. μ ννλ μ»€λ° μ΄μ μ μννλ flushκ° μ°κΈ° μ§μ° 쿼리 μνμ μ λ°νλ λμμ. μ»€λ° μμ μ΄ μλλλΌλ flushλ₯Ό νΈμΆν΄ μ§μ°λ μ°κΈ° 쿼리λ€μ μ€νν μ μμ | ||
- μ μν μ - IDENTITY μλ³μ μ λ΅μ μ¬μ©νλ μν°ν°μ insert μμ μλ μ°κΈ° μ§μ° μμ΄ λ°λ‘ μΏΌλ¦¬κ° λ°μν¨. κΈ°λ³Έ ν€ κ°μ νλνκΈ° μν¨ | ||
4. **λ³κ²½ κ°μ§** | ||
- μ°κΈ° μΏΌλ¦¬κ° μνλ μμ μ μν°ν°μ μ€λ μ·κ³Ό νμ¬ μνλ₯Ό λΉκ΅ν΄ λ³κ²½μ λ°μνκΈ° μν 쿼리λ€μ μνν¨ | ||
- λ³κ²½ κ°μ§ λν flush μμ μ μν | ||
5. **μ§μ° λ‘λ©** | ||
- μ°κ΄ κ΄κ³μΈ μν°ν°λ₯Ό μΌλ¨ νλ‘μλ‘ κ°μ Έμλ€κ° μ¬μ©νλ μμ μ μ‘°ν 쿼리λ₯Ό ν΅ν΄ λ‘λ©ν΄μ€λ μ λ΅ |