잡담소장소

JPA no session 문제 본문

Study ;3

JPA no session 문제

유부뽀 2021. 9. 13. 16:15
2021-09-13 16:08:24.657  INFO 44734 --- [    Test worker] c.b.c.d.c.service.ModelServiceTest       : Log message invocation failed: com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy [com.test.entity.IceCream#1] - no Session (through reference chain: com.test.entity.Food["icecream"]->com.test.entity.IceCream$HibernateProxy$OQ2PqbuL["price"])

model 내에 @ManyToOne으로 걸어놓은 데이터에서 계속 no session 에러가 발생했다

대충 1차 entity 조회 후 세션이 끊긴걸로 이해했는데

이 session을 그래서 어떻게 이어줘야 하는지 ㅠㅠ 한참 찾아 헤매었는데 

답은 @Transactional을 요청단위로 설정하는 것이었다 ㅠ_ㅠ

@Test
@Transactional
fun test(){
	jpaRepository.findOne(1).orElseGet(null);
}

 

반응형
Comments