public List<Drawing> getDrawingList() {
List<Drawing> drawings = drawingService.findDrawings();
for (Drawing drawing : drawings) {
drawing.getDrawingCategory().getName();
}
return drawings;
}
위 코드 실행시에러 내용입니다.
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0]->.drawing.entity.Drawing["drawingCategory"]->.drawingcategory.entity.DrawingCategory$HibernateProxy$dtz0HezH["hibernateLazyInitializer"])] with root cause
findDrawings 에서 JpaRepository가 findAll을 return 해줍니다.
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id", nullable = false)
private DrawingCategory drawingCategory;
Drawing은 DrawingCategory를 ManyToOne으로 단방향 연관관계를 맺고 있습니다.
그래서, drawing.getDrawingCateogory.getName 으로 Lazy 강제 초기화를 해주었는데 위의 에러가 나오네요..
fetch join을 사용하면 해결이 되긴 합니다만 get으로 Lazy연관관계의 값을 직접 가져와도 HibernateProxy객체가 유지되는지 궁금합니다.