Spring-data-JPA

JPA

<aside> ๐Ÿ’ก JPA๋Š” Java Persistence API์˜ ์•ฝ์ž์ด๋ฉฐ, ์ž๋ฐ” ORM ๊ธฐ์ˆ ์— ๋Œ€ํ•œ ํ‘œ์ค€ ๋ช…์„ธ์ด๋‹ค.

</aside>

์ฆ‰, JPA๋Š” ์ž๋ฐ”์—์„œ ORM์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ํ‘œ์ค€ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋ชจ์•„๋‘” ์ง‘ํ•ฉ์ด๋‹ค.

jakarta.persistence ํŒจํ‚ค์ง€๋ฅผ ํ†ตํ•ด JPA์˜ ์—ฌ๋Ÿฌ ๋ช…์„ธ๋“ค์„ ์‚ดํŽด๋ณผ ์ˆ˜ ์žˆ๋‹ค.

Untitled

JPA Architecture

์ฃผ์š” ์œ ๋‹›๋“ค

EntityManagerFacotry ์—ฌ๋Ÿฌ๊ฐ€์ง€ EntityManager instance๋“ค์„ ๊ด€๋ฆฌํ•˜๊ณ  ๋งŒ๋“œ๋Š” ์ฃผ์ฒด.(EntityManager
EntityManager persistence object์— ๋Œ€ํ•œ ์˜์†์„ฑ ์—ฐ์‚ฐ์„ ๋‹ด๋‹นํ•˜๋Š” ์ฃผ์ฒด
Entity persistence object (as records in the database). @Entity ์–ด๋…ธํ…Œ์ด์…˜์ด ์žˆ๋Š” ํด๋ž˜์Šค๋Š” JPA ์—”ํ‹ฐํ‹ฐ ํด๋ž˜์Šค๋กœ ์ •์˜ํ•จ์„ ์˜๋ฏธ
EntityTransaction ์˜์†์„ฑ ์—ฐ์‚ฐ๋“ค์ด ์œ ์ง€๋˜๋Š” ์ฃผ์ฒด. ๋”ฐ๋ผ์„œ ๊ฐ๊ฐ์˜ EntityManage๋Š” EntityTransaction์„ ๊ฐ–๋Š”๋‹ค.(one-to-one relation)
Persistence EntityManagerFactory instance๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด ์“ฐ์ž„
Query This interface is implemented by each JPA vendor to obtain relational objects that meet the criteria.

Untitled

์˜์†์„ฑ ์ปจํ…์ŠคํŠธ (Persistence Context)

<aside> ๐Ÿ’ก ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ ์žฅ์ 

  1. 1์ฐจ ์บ์‹œ ์ฒ˜๋ฆฌ

  2. ๋™์ผ์„ฑ ๋ณด์žฅ

  3. ํŠธ๋žœ์žญ์…˜์„ ์ง€์›ํ•˜๋Š” ์“ฐ๊ธฐ ์ง€์—ฐ

  4. ๋ณ€๊ฒฝ ๊ฐ์ง€

  5. ์ง€์—ฐ๋กœ๋”ฉ

</aside>