작성
·
242
0
안녕하세요. 언제나 좋은 강의 너무 감사드립니다.
다름이 아니라 본영상에 8:43초 쯤에 나오는 EntityGraphType이 FETCH 타입과 LOAD타입이 있는데요.
@EntityGraph(value ="Study.withTagsAndManagers", type = EntityGraph.EntityGraphType.FETCH)
Study findStudyWithTagsByPath(String path);
이것의 타입을 FETCH로 해서 태그를 더하는 액션을 취할경우, 다음과 같은 SQL이 발생합니다.
2020-05-17 09:34:12.745 DEBUG 8292 --- [io-8080-exec-10] org.hibernate.SQL :
select
study0_.id as id1_4_0_,
tag2_.id as id1_9_1_,
account4_.id as id1_0_2_,
study0_.closed as closed2_4_0_,
study0_.closed_date_time as closed_d3_4_0_,
study0_.full_description as full_des4_4_0_,
study0_.image as image5_4_0_,
study0_.path as path6_4_0_,
study0_.publish_date_time as publish_7_4_0_,
study0_.published as publishe8_4_0_,
study0_.recruit_update_date_time as recruit_9_4_0_,
study0_.recruiting as recruit10_4_0_,
study0_.short_description as short_d11_4_0_,
study0_.title as title12_4_0_,
study0_.use_banner as use_ban13_4_0_,
tag2_.title as title2_9_1_,
tags1_.study_id as study_id1_7_0__,
tags1_.tags_id as tags_id2_7_0__,
account4_.bio as bio2_0_2_,
account4_.email as email3_0_2_,
account4_.email_check_token as email_ch4_0_2_,
account4_.email_check_token_generated_at as email_ch5_0_2_,
account4_.email_verified as email_ve6_0_2_,
account4_.joined_at as joined_a7_0_2_,
account4_.location as location8_0_2_,
account4_.nickname as nickname9_0_2_,
account4_.occupation as occupat10_0_2_,
account4_.password as passwor11_0_2_,
account4_.profile_image as profile12_0_2_,
account4_.study_created_by_email as study_c13_0_2_,
account4_.study_created_by_web as study_c14_0_2_,
account4_.study_enrollment_result_by_email as study_e15_0_2_,
account4_.study_enrollment_result_by_web as study_e16_0_2_,
account4_.study_updated_by_email as study_u17_0_2_,
account4_.study_updated_by_web as study_u18_0_2_,
account4_.url as url19_0_2_,
managers3_.study_id as study_id1_5_1__,
managers3_.managers_id as managers2_5_1__
from
study study0_
left outer join
study_tags tags1_
on study0_.id=tags1_.study_id
left outer join
tag tag2_
on tags1_.tags_id=tag2_.id
left outer join
study_managers managers3_
on study0_.id=managers3_.study_id
left outer join
account account4_
on managers3_.managers_id=account4_.id
where
study0_.path=?
2020-05-17 09:34:12.745 TRACE 8292 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [aaaa]
2020-05-17 09:34:12.748 DEBUG 8292 --- [io-8080-exec-10] org.hibernate.SQL :
select
tags0_.account_id as account_1_1_0_,
tags0_.tags_id as tags_id2_1_0_,
tag1_.id as id1_9_1_,
tag1_.title as title2_9_1_
from
account_tags tags0_
inner join
tag tag1_
on tags0_.tags_id=tag1_.id
where
tags0_.account_id=?
2020-05-17 09:34:12.748 TRACE 8292 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [86]
2020-05-17 09:34:12.749 DEBUG 8292 --- [io-8080-exec-10] org.hibernate.SQL :
select
tag0_.id as id1_9_,
tag0_.title as title2_9_
from
tag tag0_
where
tag0_.title=?
2020-05-17 09:34:12.749 TRACE 8292 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [aaaa]
2020-05-17 09:34:12.750 DEBUG 8292 --- [io-8080-exec-10] org.hibernate.SQL :
delete
from
study_tags
where
study_id=?
2020-05-17 09:34:12.751 TRACE 8292 --- [io-8080-exec-10] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [87]
문제는 2번째 발생하는 SQL입니다.
제가 생각했을때는 tags와 managers에 관련된 SQL만 발생해야 하는데, 왜 중간에 account_tags 테이블로부터 태그 정보를 얻으려 하는지 모르겠습니다.이 테이블은 settingsController에서 태그 관련 액션시 이용되는 테이블이라고 생각하고 있습니다.
디버그해보니, @CurrentUser시점에서 불러들이는 account의 tags와 zones는 size=0임을 알수 있습니다.
...그렇다고 해도, getStudyToUPdateTag가 불러졌을때 account_tags가 불려지는 이유를 도무지 알수가 없습니다.
EntityGraphType을 FETCH가 아닌 LOAD타입으로 바꾸면 account_tags관련 SQL이 나오지 않습니다.
제가 코딩을 잘못한 것일까요? 아니면 이 단계에서는 이렇게 나오는게 정상인가요?
PS:
백기선님의 github에서 master브랜치를 디버깅 -> account_tags관련 SQL 안나옴. -> 원인분석 실패...
만일을 대비해, 제 깃헙 링크도 첨부합니다.
https://github.com/yongsoo-kim/studyolle/tree/feature/ph4_study_feature/src/main/java/com/studyolle/studyolle/study