월 17,600원
5개월 할부 시다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 미해결스프링 데이터 JPA
@ManyToOne FetchType=EAGER로 조회 시 N+1문제 발생
안녕하세요 기선님 JPA 강좌 정말 잘 보고있습니다! @ManyToOne 관계 매핑한 엔티티를 EAGER 타입으로 조회를 할때요 어떤 경우에는 조인으로 두 엔티티 정보를 한번에 쿼리하는 반면에, 각각의 엔티티를 따로 쿼리하는 경우가 있어서 EAGER 조회에서도 N+1문제가 발생하더라고요. 어떤 경우엔 조인이 되고 어떤 경우에 각각 쿼리가 발생하는지 알려주실 수 있을까요? ( 지금 껏 테스트로 추측하기로는 id 로 조회할 때는 조인 쿼리가 발생하고, 그외에는 별개 쿼리가발생하는 것 같아요) 코드랑 쿼리 결과도 첨부드릴게요 @Entity public class Post { @Id @GeneratedValue private Long id; private String name; public Post() {} public Post(String name) { this.name = name; } } @Entity public class Comment { @Id @GeneratedValue private Long id; private String title; @ManyToOne private Post post; public Comment() {} public Comment(String title, Post post) { this.title = title; this.post = post; } } @Component public class JpaRunner implements ApplicationRunner { @Autowired PostRepository postRepository; @Autowired CommentRepository commentRepository; @Transactional @Override public void run(ApplicationArguments args) { //아래 데이터가 입력된 상황 // Post post1 = new Post("A"); // Post post2 = new Post("B"); // Post post3 = new Post("C"); // postRepository.saveAll(Arrays.asList(post1, post2, post3)); // postRepository.flush(); // // Comment comment1 = new Comment("a", post1); // Comment comment2 = new Comment("a", post2); // Comment comment3 = new Comment("a", post3); // // commentRepository.saveAll(Arrays.asList(comment1, comment2, comment3)); // commentRepository.flush(); commentRepository.findById(1L); commentRepository.findByTitle("a"); } } 실행된 쿼리 Hibernate: select comment0_.id as id1_0_0_, comment0_.post_id as post_id3_0_0_, comment0_.title as title2_0_0_, post1_.id as id1_1_1_, post1_.name as name2_1_1_ from comment comment0_ left outer join post post1_ on comment0_.post_id=post1_.id where comment0_.id=? 2018-09-18 02:32:41.805 INFO 5078 --- [ main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory Hibernate: select comment0_.id as id1_0_, comment0_.post_id as post_id3_0_, comment0_.title as title2_0_ from comment comment0_ where comment0_.title=? Hibernate: select post0_.id as id1_1_0_, post0_.name as name2_1_0_ from post post0_ where post0_.id=? Hibernate: select post0_.id as id1_1_0_, post0_.name as name2_1_0_ from post post0_ where post0_.id=? Hibernate: select post0_.id as id1_1_0_, post0_.name as name2_1_0_ from post post0_ where post0_.id=?
- 미해결스프링 데이터 JPA
pom.xml에서 자동완성을 사용하시던데요!
기본설정에서는 안되는거죠? ^^어떻게 하는지 알려주시면 좋겠네요~
- 미해결스프링 데이터 JPA
[fetch]팔로우/팔로우 기능 테이블 관계 맵핑
팔로우/ 팔로잉 기능을 구현하려고 합니다.User Entity, Follow Entity를 생성[팔로워 기능]User테이블에 @ManyToOne(name) , List[팔로잉 기능]User테이블에 @ManyToOne(name) , List, mappedby="user", cascadeFollow테이블에 @joinColumn(foreignKey=@ForeignKey(name="fk_follow_parent_user_id")이 정도 까지 생각해 봤는데 맞는지도 모르겠고 이런식으로 구성해도 될지 모르겠습니다.힌트 주시면 감사하겠습니다.
- 미해결스프링 데이터 JPA
JPA에서 Multiple datasource 를 어떻게 설정하는지 궁금합니다.
안녕하세요! 선생님! 강의 잘 듣고 있습니다. 이렇게 질문 드린건 다름 아니고 JPA에서는 어떤식으로 멀티 DB를 설정하는지 JPA는 멀티 DB를 설정하지 않아도 괜찮은지 궁금해서 질문드렸고 선생님은 어떤식으로 멀티 DB를 구성하셨는지 궁금해서 ㅎㅎ 질문드렸습니다.
- 미해결스프링 데이터 JPA
JPA에서 Multiple datasource 를 어떻게 설정하는지 궁금합니다.
안녕하세요! 선생님! 강의 잘 듣고 있습니다. 이렇게 질문 드린건 다름 아니고 JPA에서는 어떤식으로 멀티 DB를 설정하는지 JPA는 멀티 DB를 설정하지 않아도 괜찮은지 궁금해서 질문드렸고 선생님은 어떤식으로 멀티 DB를 구성하셨는지 궁금해서 ㅎㅎ 질문드렸습니다.
- 미해결스프링 데이터 JPA
Transient, Detached 상태 질문드립니다.
엔티티의 @Id 프로퍼티를 찾는다. 해당 프로퍼티가 null이면 Transient 상태로판단하고 id가 null이 아니면 Detached 상태로 판단한다.@Id 프로퍼티가 단순히 null인지 여부에 따라서 Transient, Detached로 판단할 경우ID 생성전략을 데이터베이스에 위임하지 않고 객체가 직접하는 경우에는 모두 Detached로 받아 들이는 건가요?아니면 Id 생성 전략에 따라서 그 판단 기준도 다른건가요?
- 미해결스프링 데이터 JPA
플러시 관련 질문드립니다.
findAll 같은 메서드는 플러시를 강제 발생시키는 것은 명확한 이유가 있다고 생각합니다.(강의 말씀 처럼 싱크를 맞춰야 하기 때문에) 그런데 식별자로 조회하는 findOne, findById 같은 메서들은 왜 플러시를 발생시키지 않을까요 ? 제 생각에는 User user = userRepository.save(user); // 아직 플러시를 발생시키지 않았음으로 데이터베이스에는 없는 상태userRepository.findById(user.getId()); // 위에서 플러시를 발생시키지 않았기 때문에 조회되지도 않을거 같습니다. 영속성 컨텍스트가 1차 캐시를 가지고 있기 때문에 플러시를 실행하지 않는거 같습니다. 혹시 이런 이유인가요? 아니면 다른 이유가 있을까요?
- 미해결스프링 데이터 JPA
7.쿼리 영상이 아니라 6.Fetch 영상이 나오고 있습니다.
안녕하세요 강좌 잘 듣고 있습니다.영상이 잘 못 나오고 있으니 확인 부탁드립니다.^^