inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

풀잎님의 게시글

풀잎 풀잎

@fullleaf

수강생
-
수강평
-
강의 평점
-

게시글 11

질문&답변

Collection type으로 Set 대신 List를 사용하는 이유가 있는지요?

말씀해주신 내용을 확인해본 결과로, 혹시 찾아오신 분들께 도움이 될까 싶어 공유합니다. 결론적으로는 말씀해주신대로 (양방향 연관관계 + List)를 취하면 불필요한 fetch가 없을 것 같습니다. 1. 값 타입의 Collection을 변경시킬 경우 말씀대로 Set에서는 데이터가 로딩되고 List에서는 데이터가 로딩되지 않음을 확인하였습니다. 2. 반면 1:N 단방향 연관관계에서는 Collection을 변경시킬 경우 Set, List 모두 데이터가 로딩됨을 확인하였습니다. (추가) 3. 우리가 N:1 양방향 연관관계의 mappedBy에서도 Set에서만 데이터가 로딩된다는 내용의 Documentation을 찾고 확인하였습니다. 다만 해당 자료는 최근 버전에서 없어지거나 이동한 것으로 보입니다. 옛날 버전(Hibernate 4.3): https://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch20.html#performance-collections-mostefficientupdate 최근 버전(Hibernate 5.4): https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#best-practices-mapping-associations ===== 2022/05/29 수정 - Github Gist로 관련 파일만 옮겼습니다. 제가 사용한 코드입니다 ( https://gist.github.com/nightlyherb/00447a2ab196dcc3d5cd9e9b01f313ef ) 관련 부분 DemoRunner.java 결과 ===== Init Lazy Parent ===== Hibernate: select parent0_.id as id1_1_0_ from parent parent0_ where parent0_.id=? ===== Embeddable Child Set ===== Hibernate: select embeddable0_.parent_id as parent_i1_2_0_, embeddable0_.value as value2_2_0_ from parent_embeddable_child_list embeddable0_ where embeddable0_.parent_id=? ===== Embeddable Child List ===== ===== Entity Child Set ===== Hibernate: select entitychil0_.set_parent_id as set_pare2_0_0_, entitychil0_.id as id1_0_0_, entitychil0_.id as id1_0_1_ from entity_child entitychil0_ where entitychil0_.set_parent_id=? ===== Entity Child List ===== Hibernate: select entitychil0_.list_parent_id as list_par3_0_0_, entitychil0_.id as id1_0_0_, entitychil0_.id as id1_0_1_ from entity_child entitychil0_ where entitychil0_.list_parent_id=? ===== Bidirectional Mapping Child Set ===== Hibernate: select bidirectio0_.set_parent_id as set_pare3_0_0_, bidirectio0_.id as id1_0_0_, bidirectio0_.id as id1_0_1_, bidirectio0_.list_parent_id as list_par2_0_1_, bidirectio0_.set_parent_id as set_pare3_0_1_ from bidirectional_mapping_child bidirectio0_ where bidirectio0_.set_parent_id=? ===== Bidirectional Mapping Child List ===== ===== End ===== (그 후 Embeddable Child List의 테이블 전부 날리고 다시 insert하는 쿼리 수행)

좋아요수
11
댓글수
4
조회수
2633

고민있어요

강의록 수정안

좋아요수
0
댓글수
1
조회수
317

질문&답변

코드 복사 가능한 자료

깔끔하게 정렬된 jumbotron-narrow.css는 여기에서 받으실 수 있습니다: https://getbootstrap.com/docs/3.4/examples/jumbotron-narrow/jumbotron-narrow.css

좋아요수
2
댓글수
3
조회수
500

질문&답변

foreach 단축키

지나가시는 분들을 위해 맥락을 적자면 강의 3:30에 나오는 내용이고 연관된 단축키로 orderItems.for (iter과 동일) / orderItems.fori / orderItems.forr 등이 있네요

좋아요수
4
댓글수
2
조회수
334