묻고 답해요
141만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결실전! 스프링 부트와 JPA 활용2 - API 개발과 성능 최적화
1:N 계층구조 테이블들 간에 Fetch 조인 사용 질문 드립니다.
안녕하세요. 열심히 강의를 듣고 있는 수강생입니다!궁금한게 있습니다.현재 실무에서 사용하고 있는 구조를 좀더 개선시키고 싶어서 열심히 노력중인데요.현재 상황을 말씀 드리겠습니다.A, B, C, D 테이블이 있습니다.각 entitiy 클래스 별로 OneToMany로 A-B, B-C, C-D 이런식으로 Relation이 걸려 있습니다.현재 기준으로는 각 OneToMany 별로 BatchSize=1000 & FetchType=Eager로 적용이 되어있는데요.이렇다 보니, A 테이블 조회시 조회된 ID 기준으로 하위 테이블들에 대해서 IN쿼리가 몇개씩 불려지게 됩니다. 그래서 Fetch 조인을 통해서 한번에 가져오는 방식으로 바꿔보려고 개선을 하려고 했는데요.예를 들면select a.* from A aleft fetch join a.B bleft fetch join b.C cleft fecth join c.D d이런식으로 하려고했더니 컴파일 단계에서 MultipleBagFetchException이 발생 하였습니다.그래서 찾아보니 fecth 조인 사용할 경우에는 oneToMany로 걸리는 대상이 2개 이상이면위와같은 Exception을 떨군다고 하더라구요..(카티션 곱 이슈로 인한 하이버네이트에서 사전에 미리 막는..) 그래서 결국에는 A-B까지만 Fetch로 빼고 나머지 B-C, C-D는 기존 그대로 Eager 전략으로기존과 동일하게 조회되도록 조금이나마 개선은 했는데요..B-C, C-D를 lazy로 바꾸니 N+1이 발생했구요.. N+1해소 하는 방법으로 Fecth조인을 쓰자니위와같은 Exception이 발생을 하구요..어떻게 하면 좋을까요.. 도와주세요!
-
미해결
fetch join 질문
Fetch join에 있어 궁금한 점이 있어서 남깁니다.Fetch join을 사용할 때 서로 떨어진 테이블끼리도 fetch join을 사용할 수 있는지 궁금합니다.일단 페이징 같은 기능이 없다는 가정하에,예를 들어 Entity 1 - Entity 2가 다대일의 관계이고, Entity 2 - Entity 3이 다대일의 관계로 묶여있다면,select * from Entity1 e1 join fetch e.Entity2 join fetch e.Entity2.Entity3;위와 같이 join fetch e.Entity2.Entity3; 이러한 fetch join 문이 가능한가에 대해서 궁금합니다. 만약 이것이 불가능하다면 저러한 상황에서 Entity2를 기준으로 쿼리를 하는 것 말고 다른 방법으로 최적화 할 수 있는 방법이 있는지 궁금합니다.
-
해결됨실전! 스프링 부트와 JPA 활용2 - API 개발과 성능 최적화
OneToMany 페치 조인 문제
현재 그룹 조회 API를 구현하고 있습니다. 메신저 앱 처럼 그룹 조회시 그룹 아이디, 그룹 이름, 그룹 이미지, 그룹에 속해있는 멤버들 (컬렉션)을 조회해 와야합니다. 여기서 강의의 V3 내용처럼 1 + N 문제를 해결하기 위해서 다음과 같이 페치 조인을 사용하여 쿼리문을 작성하였습니다. TeamRepository.java @Transactional(readOnly = true) public interface TeamRepository extends JpaRepository<Team, Long> { @Query("select distinct t from Team t" + " join fetch t.id id" + " join fetch t.groupName gn" + " join fetch t.imageUrl iu" + " join fetch t.teamMembers tm" + " join fetch tm.member m" + " where tm.id = :id") List<SearchGroupResponse> findGroupInfoWithMembers(@Param("id") Long id); } `Team.java` @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Team extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; @Column(length = 30) private String groupName; @Lob private String imageUrl; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "place_id") private Place place; @OneToMany(mappedBy = "team", cascade = CascadeType.ALL) private final List<TeamMember> teamMembers = new ArrayList<>(); private LocalDateTime date; } TeamMember.java @Entity @Getter @Table(name = "GroupMember") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class TeamMember extends BaseEntity { @ManyToOne(fetch = LAZY) @JoinColumn(name = "member_id") private Member member; @ManyToOne(fetch = LAZY) @JoinColumn(name = "team_id") private Team team; @Column(length = 100) private String curLocate; private char arrived; public TeamMember(Member member, Team team) { this.member = member; this.team = team; } } 강의 V3-1 과 같이 컬랙션 데이터는 지연 로딩과 BatchSize를 적용하여 성능 최적화를 해줘야 된다고 배웠지만 일단은 V3를 적용해 보고 개선해 보고자 이렇게 코드를 작성해 보았습니다. 하지만 다음과 같은 에러가 발생하였고 이를 해결하고자 여러 구글링을 해보았지만 해답을 찾지 못하여 질문 남겨봅니다. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'promiseController' defined in file [/Users/sanha/SpringStudy/promisor/out/production/classes/promisor/promisor/domain/promise/api/PromiseController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'promiseService' defined in file [/Users/sanha/SpringStudy/promisor/out/production/classes/promisor/promisor/domain/promise/service/PromiseService.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teamRepository' defined in promisor.promisor.domain.team.dao.TeamRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)! Reason: Validation failed for query for method public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)! at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.15.jar:5.3.15] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.3.jar:2.6.3] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-2.6.3.jar:2.6.3] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) ~[spring-boot-2.6.3.jar:2.6.3] at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.3.jar:2.6.3] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.6.3.jar:2.6.3] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.6.3.jar:2.6.3] at promisor.promisor.PromisorApplication.main(PromisorApplication.java:12) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.6.3.jar:2.6.3] Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'promiseService' defined in file [/Users/sanha/SpringStudy/promisor/out/production/classes/promisor/promisor/domain/promise/service/PromiseService.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teamRepository' defined in promisor.promisor.domain.team.dao.TeamRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)! Reason: Validation failed for query for method public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)! at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.15.jar:5.3.15] ... 24 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teamRepository' defined in promisor.promisor.domain.team.dao.TeamRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)! Reason: Validation failed for query for method public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)! at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.15.jar:5.3.15] ... 38 common frames omitted Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)! Reason: Validation failed for query for method public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)! at org.springframework.data.repository.query.QueryCreationException.create(QueryCreationException.java:101) ~[spring-data-commons-2.6.1.jar:2.6.1] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:106) ~[spring-data-commons-2.6.1.jar:2.6.1] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(QueryExecutorMethodInterceptor.java:94) ~[spring-data-commons-2.6.1.jar:2.6.1] at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na] at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) ~[na:na] at java.base/java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1056) ~[na:na] at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:na] at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na] at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na] at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na] at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na] at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.mapMethodsToQuery(QueryExecutorMethodInterceptor.java:96) ~[spring-data-commons-2.6.1.jar:2.6.1] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$new$0(QueryExecutorMethodInterceptor.java:86) ~[spring-data-commons-2.6.1.jar:2.6.1] at java.base/java.util.Optional.map(Optional.java:258) ~[na:na] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.<init>(QueryExecutorMethodInterceptor.java:86) ~[spring-data-commons-2.6.1.jar:2.6.1] at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:364) ~[spring-data-commons-2.6.1.jar:2.6.1] at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:322) ~[spring-data-commons-2.6.1.jar:2.6.1] at org.springframework.data.util.Lazy.getNullable(Lazy.java:230) ~[spring-data-commons-2.6.1.jar:2.6.1] at org.springframework.data.util.Lazy.get(Lazy.java:114) ~[spring-data-commons-2.6.1.jar:2.6.1] at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:328) ~[spring-data-commons-2.6.1.jar:2.6.1] at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:144) ~[spring-data-jpa-2.6.1.jar:2.6.1] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.15.jar:5.3.15] ... 49 common frames omitted Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List promisor.promisor.domain.team.dao.TeamRepository.findGroupInfoWithMembers(java.lang.Long)! at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:96) ~[spring-data-jpa-2.6.1.jar:2.6.1] at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:66) ~[spring-data-jpa-2.6.1.jar:2.6.1] at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:51) ~[spring-data-jpa-2.6.1.jar:2.6.1] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:163) ~[spring-data-jpa-2.6.1.jar:2.6.1] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:252) ~[spring-data-jpa-2.6.1.jar:2.6.1] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:87) ~[spring-data-jpa-2.6.1.jar:2.6.1] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:102) ~[spring-data-commons-2.6.1.jar:2.6.1] ... 71 common frames omitted Caused by: java.lang.NullPointerException: Cannot invoke "org.hibernate.hql.internal.ast.tree.FromElement.setAllPropertyFetch(boolean)" because "fromElement" is null at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:431) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3990) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3776) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3654) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:737) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:593) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:330) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:278) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:276) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:636) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:748) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:114) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na] at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:362) ~[spring-orm-5.3.15.jar:5.3.15] at com.sun.proxy.$Proxy139.createQuery(Unknown Source) ~[na:na] at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:90) ~[spring-data-jpa-2.6.1.jar:2.6.1] ... 77 common frames omitted
-
미해결실전! 스프링 부트와 JPA 활용2 - API 개발과 성능 최적화
fetch join 일관성
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.1. 강의 내용과 관련된 질문을 남겨주세요.2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.(자주 하는 질문 링크: https://bit.ly/3fX6ygx)3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.=========================================[질문 템플릿]1. 강의 내용과 관련된 질문인가요? (예/아니오)2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)[질문 내용]여기에 질문 내용을 남겨주세요. jpa활용 1편에서 fetch join 일관성 관련해서 아직 확실하지 이해하지 못한 것 같아서 활용 2편을 듣다가 질문이 생겼고 다른 수강생분이 올린 질문 내용과 답변을 보다가 궁금한 것이 생겨 질문드렸습니다. https://www.inflearn.com/questions/15876 위 링크에 있는 답변을 읽어보니 fetch join의 대상은 on,where 등에서 필터링 조건을 사용하면 안되지만 일관성이 깨지지 않는다면 사용할 수 있다고 답변을 주신 것 같습니다. 코드 1 select m from Member m join fetch m.team t where t.name=:teamName 코드 2 select t from Team t join fetch t.members m where m.username =:username (질문) 또한 위 링크에서 코드 1은 객체의 상태와 db의 상태의 일관성이 깨지지 않고 코드 2는 일관성이 깨진다고 답변해주셨고 위 두개의 코드가 왜 일관성이 깨지고,깨지지 않는지 생각해보았고 제가 생각한 것이 맞는지 알고 싶어서 질문을 드렸습니다. 코드 1이 일관성이 깨지지 않는다고 생각한 이유 memberA - team1 memberB - team1 memberC - team2 로 DB에 데이터가 있다고 가정 조인 대상의 필터링을 제공하여 조회결과가 team1만 조회하게 되면 memberA = {team1} memberB = {team1} 와 같은 결과를 얻게 되고 memberA를 조회할 경우 team1이 조회되고 mebmerB가 조회할 경우 team1이 조회됨으로 코드1은 일관성이 깨지지 않는다고 생각했습니다. 코드 2가 일관성이 깨진다고 생각한 이유 team1 - memberA team1 - memberB team1 - memberC 로 DB에 데이터가 있다고 가정 조인 대상의 필터링을 제공하여 조회 결과가 memberA, memberC만 조회하게 되면 team1 = {memberA, memberC}와 같은 결과를 얻게 되고 team1을 조회할 경우 memberC가 조회되지 않아 코드2는 일관성이 깨진다고 생각했습니다.
-
해결됨실전! 스프링 데이터 JPA
fetch join 수행시 우선순위?
항상 강의 잘 듣고 있습니다. 감사합니다! fetch join을 할 때 기본적으로 left outer join이 수행된다고 하셨는데 그 전 강의에서는 대부분 Inner join으로 수행됐던것같아서. 질문드렸습니다! 수행하는 우선순위가 따로 있는건가요?