2022-12-06 21:34:42.490 ERROR 9648 --- [nio-8081-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.hibernate.LazyInitializationException: could not initialize proxy [server.twalk.PvP.entity.Status#4] - no Session] with root cause
org.hibernate.LazyInitializationException: could not initialize proxy [server.twalk.PvP.entity.Status#4] - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:176) ~[hibernate-core-5.6.5.Final.jar!/:5.6.5.Final]
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:322) ~[hibernate-core-5.6.5.Final.jar!/:5.6.5.Final]
at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor.intercept(ByteBuddyInterceptor.java:45) ~[hibernate-core-5.6.5.Final.jar!/:5.6.5.Final]
at org.hibernate.proxy.ProxyConfigurationHibernateProxyreadMyJalking3(MemberService.java:149) ~[classes!/:na] at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178) ~[na:na] at java.base/java.util.ArrayListArrayListSpliterator.forEachRemaining(ArrayList.java:1625) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[na:na]
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
public List<JalkingDto> readMyJalking(Long id) {
Member member = memberRepository.findById(id).orElseThrow(MemberNotFoundException::new);
Set<Jalking> jalkingList = new HashSet<>();
List<Jalking> jalkingsRec = jalkingRepository.findByReceiverOrderByCreatedAtDesc(member).stream()
.filter( jalking ->
// 이 부분에서 세션을 찾을 수 없다는 에러가 뜬다.
jalking.getStatus().getStatusType().name().equals("COMPLETE") )
.collect(Collectors.toList());
List<Jalking> jalkingsReq = jalkingRepository.findByRequesterOrderByCreatedAtDesc(member).stream()
.filter( jalking -> jalking.getStatus().getStatusType().name().equals("COMPLETE") )
.collect(Collectors.toList());
jalkingList.addAll(jalkingsRec);
jalkingList.addAll(jalkingsReq);
return JalkingDto.toDtoList(jalkingRepository.findByJalkings(new ArrayList<>(jalkingList)));
}
지연 조회 시점까지 세션을 유지 시켜주기 위해서 @Transactional 어노테이션을 마이페이지 조회 method 위에 추가했다.
reference :
https://velog.io/@ariul-dev/Spring-LazyInitializationException-could-not-initialize-proxy