Search
Duplicate
โ˜•

private method๊ฐ€ Transactional ์„ ํƒ€์ง€ ์•Š๋Š” ์ด์œ 

Transactional ์–ด๋…ธํ…Œ์ด์…˜์œผ๋กœ ์ธํ•ด ํ”„๋ก์‹œ ๊ฐ์ฒด(๋ณดํ†ต ์„œ๋น„์Šค)๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.
ParentA(์„œ๋น„์Šค), ChildB(ํ”„๋ก์‹œ) ๊ฐ€ ์žˆ์„ ๋•Œ ChildB ์—์„œ ParentA ๋ฅผ super๋กœ ๋ถ€๋ฅด๋ฉด ParentA ์—์„œ this ๋ฉ”์„œ๋“œ๋Š” ChildB ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.
JPA ์—์„œ๋Š” ๊ทธ๋ž˜์„œ CbildB ์—์„œ ParentA ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ super ๋กœ ํ˜ธ์ถœํ•˜์ง€ ์•Š๊ณ  ํ•„๋“œ์— ์ดˆ๊ธฐํ™”ํ•œ ParentA ๋กœ ํ˜ธ์ถœํ•œ๋‹ค.
๊ทธ๋ž˜์„œ ์„œ๋น„์Šค์—์„œ ๋‚ด๋ถ€ ํผ๋ธ”๋ฆญ ๋ฉ”์„œ๋“œ a, b ๊ฐ€ ์žˆ๊ณ  a ๊ฐ€ b ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ, b์— Transactional ์ด ๊ฑธ๋ ค์žˆ๋‹ค๊ณ  ํ•˜๋”๋ผ๋„ ํ†ตํ•˜์ง€ ์•Š๋Š”๋‹ค. ์™œ๋ƒํ•˜๋ฉด a ๊ฐ€ b ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ transaction์ด ๊ฐ์‹ธ์ง„ ํ”„๋ก์‹œ์˜ b ๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๊ณ  ๋ฐ”๋กœ ์ž์‹ (์„œ๋น„์Šค) ์˜ b ๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

์š”์•ฝ

์ƒ์†์ด ์•„๋‹Œ ์กฐํ•ฉ์„ ์ด์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค!
JDK Dynamic Proxy์€ ์ƒ์†, CGLIB ์€ ์กฐํ•ฉ