Springboot/Jpa

jpa lazy사용시 jpa could not initialize proxy - no session 에러

디비드킴 2022. 4. 4. 12:31

두가지 방법이 있다
1.해당 함수 위에 @Transactional추가
-https://jforj.tistory.com/98

[JPA] could not initialize proxy - no Session 에러

안녕하세요. J4J입니다. JPA를 사용하다가 연관관계 매핑을 위해 @OneToMany 어노테이션을 추가한 뒤 findAll() 메서드를 테스트했는데 다음과 같은 에러가 저를 반겼습니다. "failed to lazily initialize a coll

jforj.tistory.com

2.application.properties에 spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true추가
-https://stackoverflow.com/questions/36583185/spring-data-jpa-could-not-initialize-proxy-no-session-with-methods-marke

Spring Data JPA - "could not initialize proxy - no Session" - With Methods marked as transactional

I have a model that has a pretty large graph of sub entities and hibernate ends up making around 9 statements to lazily fetch all of the data needed but about 4 levels deep I get a "could not initi...

stackoverflow.com