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]->jpabook.jpashop.domain.Order["member"]->jpabook.jpashop.domain.OrderItem["item"]->jpabook.jpashop.domain.Order["delivery"]->jpabook.jpashop.domain.Member$HibernateProxy$Xrie5JVt["hibernateLazyInitializer"])] with root cause
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]->jpabook.jpashop.domain.Order["member"]->jpabook.jpashop.domain.Member$HibernateProxy$Xrie5JVt["hibernateLazyInitializer"])
spring:
jackson:
serialization:
fail-on-empty-beans: false
에러 나는 엔티티 설정 Lazy - > EAGER로 변경, 좋은방법 아님
jpabook.jpashop.domain.Order["member"] -> @ManyToOne(fetch = EAGER)
jpabook.jpashop.domain.OrderItem["item"] -> @ManyToOne(fetch = EAGER)
jpabook.jpashop.domain.Order["delivery"] -> @OneToOne(fetch = EAGER)
그래도 에러 발생 시, 해당 컬럼에 @JsonIgnore 추가
다 싫으면, Hibernate 5 Module 라이브러리 등록 / Bean 등록 하면 됨
가장 좋은건, Lazy 강제 초기화 하면 됨
@GetMapping("/api/v1/simple-orders")
public List<Order> ordersV1() {
List<Order> all = orderRepository.findAllByString(new OrderSearch());
for (Order order : all) {
order.getMember().getName(); //Lazy 강제 초기화
order.getDelivery().getAddress(); //Lazy 강제 초기화
}
return all;
}