Search
β˜•

findById ν•˜λ©΄ 무슨 일이 μΌμ–΄λ‚ κΉŒ

처음일 λ•Œ

SessionImpl μ—μ„œ fireLoad() λ₯Ό ν•œλ‹€.
fireLoad() μ—μ„œ fireLoadNoChecks() λ₯Ό μˆ˜ν–‰ν•œλ‹€.
fireLoadNoChecks() μ—μ„œ fastSessionServices.eventListenerGroup_LOAD.fireEventOnEachListener( event, loadType, LoadEventListener::onLoad ); λ₯Ό ν˜ΈμΆœν•œλ‹€.
fireEventOnEachListener() λŠ” EventListenerGroupImpl 의 λ©”μ„œλ“œμ΄κ³ , eventType 은 load 이닀.
λ“±λ‘λœ listener 듀을 ν™•μΈν•˜λŠ”λ° DefaultLoadEventListener 밖에 μ—†λ‹€.
LoadEventListener::onLoad λ₯Ό ν˜ΈμΆœν•œλ‹€.
DefaultLoadEventListener
onLoad() μ—μ„œλŠ” persister(λ°˜ν™˜ 객체) λ₯Ό μ°Ύκ³  doOnLoad() 호좜
doOnLoad() μ—μ„œλŠ” persister 와 identifier λ₯Ό κ°€μ§„ entityKey λ₯Ό μ°Ύκ³  proxyOrLoad() 호좜
proxy 인지 ν™•μΈν•˜κ³  return a newly loaded object 이면 load() λ₯Ό 호좜
load() μ—μ„œ doLoad() 호좜
doLoad() μ—μ„œ 1μ°¨ μΊμ‹œ(SessionCache), 2μ°¨ μΊμ‹œ(SecondLevelCache) 확인 ν›„ μ—†μœΌλ©΄ loadFromDatasource() 호좜
loadFromDatasource() μ—μ„œ persister.load() μˆ˜ν–‰
AbstractEntityPersister
load() μ—μ„œ doLoad() μˆ˜ν–‰ β†’ 두 λ©”μ„œλ“œ λ‹€ parameter λ˜‘κ°™μŒ;; 그럼 μ™œ load() λ₯Ό ν˜ΈμΆœν•˜λŠ”κ±°μ§€;;
getAppropriateLoader() λ₯Ό ν˜ΈμΆœν•˜μ—¬ EntityLoader μ°Ύκ³  EntityLoader μ—κ²Œ load() 호좜
Abstract~~Loader
load() μ—μ„œ QueryParameters 객체 μƒμ„±ν•˜κ³  executeLoad() 호좜
executeLoad() μ—μ„œ 일단 μ˜μ†μ„± μ»¨ν…μŠ€νŠΈμ˜ beforeLoad() λ©”μ„œλ“œλ₯Ό 톡해 load count λ₯Ό 1 μ¦κ°€μ‹œν‚΄
sql μ „μ²˜λ¦¬ν•˜κ³  prepareQueryStatement() 호좜
StatementPreparerImpl μ—μ„œ preparedStatement 생성
μƒμ„±λœ ps 에 bind parameter 함
getResultSet() ν˜ΈμΆœν•˜κ³  ν•΄λ‹Ή λ©”μ„œλ“œμ—μ„œ extract() 호좜
extract() λŠ” ResultSetReturnImpl 의 λ©”μ„œλ“œμ΄κ³  μ—¬κΈ°μ„œ ps 의 JdbcPreparedStatement 의 executeQuery() λ©”μ„œλ“œ 호좜!!
DefaultLoadEventListener 의 67λ²ˆμ€„ primitive 라면 μ–΄λ–¨μ§€ 확인, 61번 getPersister() 확인

μ˜μ†μ„± μ»¨ν…μŠ€νŠΈμ— μžˆμ„ λ•Œ

DefaultLoadEventListener 의 doOnLoad() 1μ°¨ μΊμ‹œ(SessionCache) ν™•μΈν•˜κΈ° μœ„ν•΄
CacheEntityLoaderHelper.INSTANCE.loadFromSessionCache( event, keyToLoad, options ); 호좜
loadFromSessionCache() μ—μ„œ session.getEntityUsingInterceptor( keyToLoad ); 호좜
getEntityUsingInterceptor() μ—μ„œ persistenceContext.getEntity( key ); 호좜 key λŠ” EntityKey 객체
그럼 StatefulPersistenceContext 의 entitiesByKey(HashMap) μ—μ„œ key 둜 확인