두가지 방법이 있다
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

'Springboot > Jpa' 카테고리의 다른 글
JPA 다중 기본키(복합키) 그리고 왜래키 기본키 같이 쓰기 (0) | 2022.05.15 |
---|---|
vscode querydsl Qclass classNotFound 에러 (0) | 2022.04.04 |
@oneToMany foreign key constraint fails 해결하기 (0) | 2022.04.04 |
jpa 지연로딩을 사용하자 (0) | 2022.04.04 |
vscode에서 Jpa와 query dsl Qclass만들기 (0) | 2022.04.03 |