Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPA - LazyInitializationException 문제, 해결 #36

Open
bbeomgeun opened this issue Mar 24, 2022 · 0 comments
Open

JPA - LazyInitializationException 문제, 해결 #36

bbeomgeun opened this issue Mar 24, 2022 · 0 comments
Labels
bug 버그 발견 question Further information is requested

Comments

@bbeomgeun
Copy link
Contributor

이슈 내용

  • User를 JPARepository에서 꺼내지않고, 토큰값을 이용해서 가져온 뒤, 해당 user의 게시글을 조회했다.
  • LazyInitializationException이 발생

문제 해결

  • LazyInitializationException은 간단히 말해서, 영속성 컨텍스트에 해당 객체가 없는데 참조해서 생기는 문제이다.
  • 나는 User를 JPARepository를 통해서 가져오지 않았기에, 애초에 1차캐시에 존재하지 않았다.
  • 그런데 해당 객체의 post를 조회하는 쿼리를 날렸으니 exception이 발생한 것이다.
  • 따라서, User를 Repository에서 꺼내서 영속성 컨텍스트에 넣어줬더니 문제해결.

참고 사항

- https://velog.io/@oenomel87/JPA-LazyInitializationException
@bbeomgeun bbeomgeun added bug 버그 발견 question Further information is requested labels Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 버그 발견 question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant