Search
Duplicate
โ˜•

persist vs merge

save() ๋ช…์‹œ ์‹œ SimpleJpaRepository ์˜ save() ๋ฉ”์„œ๋“œ์—์„œ entityInformation.isNew(entity) ๋ถ„๊ธฐ๋ฌธ์„ ํ†ตํ•ด em.persist() ์ธ์ง€ em.merge() ์ธ์ง€ ํŒ๋ณ„ํ•œ๋‹ค.
isNew() ๋ฉ”์„œ๋“œ

Persist

DefaultPersistEventListener ์—์„œ onPersist ์‹œ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ Event ์™ธ์—๋„ Cache ๋กœ ํ™œ์šฉํ•  IdentityHashMap ๊ฐ์ฒด๊ฐ€ ์ถ”๊ฐ€๋กœ ํ•„์š”ํ•˜๋‹ค.

Merge

DefaultPersistEventListener ์—์„œ onMerge ์‹œ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ Event ์™ธ์—๋„ Cache ๋กœ ํ™œ์šฉํ•  MergeContext(IdentityHashMap ์„ ๊ฐ์‹ผ ๊ฐ์ฒด์ธ๋“ฏ) ๊ฐ์ฒด๊ฐ€ ์ถ”๊ฐ€๋กœ ํ•„์š”ํ•˜๋‹ค.
switch - case ๋กœ detach, persistent ๋ฅผ ๊ตฌ๋ถ„ํ•œ๋‹ค.

detach

detach ์ƒํƒœ(clear ํ•œ ์ƒํƒœ)๋ผ๋ฉด select ๋ฅผ ๋จผ์ € ํ•ด์„œ ์˜์†์„ฑ์— ์ €์žฅํ•œ๋‹ค.

persistent

โ†’ merge ์ธ ๊ฒฝ์šฐ์—๋Š” cache ์— ๋„ฃ์–ด๋†“๊ธฐ๋งŒ ํ•˜๊ณ  ์ฟผ๋ฆฌ๊ฐ€ ์‹ค์ œ๋กœ ๋‚˜๊ฐ€์ง€๋Š” ์•Š๋Š”๋‹ค.
flush ๋‚˜ ๋”ํ‹ฐ์ฒดํ‚น ์‹œ์ ์—์„œ ์ฟผ๋ฆฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”๋“ฏ!

cascade ๋Š”?

AbstractSaveEventListener ์˜ performSaveOrReplicate() ์„ ์ˆ˜ํ–‰ํ•  ๋•Œ
โ€ข
ํ•ด๋‹น entity ์ „์— cascade ํ•ด์•ผ ํ•˜๋ฉด cascadeBeforeSave()
โ€ข
ํ•ด๋‹น entity save ๋Š” addInsertion()
โ€ข
ํ•ด๋‹น entity ํ›„์— cascade ํ•ด์•ผ ํ•˜๋ฉด cascadeAfterSave()
flush event listener ์—์„œ
LinkedHashMap<Class<? extends Executable>,ListProvider> EXECUTABLE_LISTS_MAP
๋งํฌ๋“œํ•ด์‹œ๋งต์œผ๋กœ ์ˆœ์„œ๊ฐ€ ์ •ํ•ด์ ธ ์žˆ๋‹ค!
static {} ์œผ๋กœ ์ˆœ์„œ๋Œ€๋กœ ๋„ฃ๋Š”๋‹ค
1.
์—†๋Š” id ๋ผ๋ฉด?
2.
๋”ํ‹ฐ์ฒดํ‚น์€?