org.springframework.orm.jpa.JpaSystemException: HHH000142: Bytecode enhancement failed: .LocalWebUserEntity; nested exception is org.hibernate.HibernateException: HHH000142: Bytecode enhancement failed: .web.localweb.domain.LocalWebUserEntity
원인: constructor 가 private 여서 발생한 문제.
해결
@NoArgsConstructor(access = AccessLevel.PRIVATE)
to
@NoArgsConstructor(access = AccessLevel.PROTECTED)
org.springframework.web.util.NestedServletException: 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]->.localweb.domain.LocalWebUserEntity$HibernateProxy$gpLnupz6["$$_hibernate_interceptor"])
원인: 단반향으로 주인이 지연 처리로 설정되어 있는 경우로 Jackson 에서 직렬화 하지못하는 걸로 판단
해결
jackson 기본 라이브러리에서 해결하지 못해 플러그인 사용
https://github.com/FasterXML/jackson-datatype-hibernate
public class HibernateAwareObjectMapper extends ObjectMapper {
public HibernateAwareObjectMapper() {
registerModule(new Hibernate5Module());
}
}
@Bean
public HttpMessageConverter<Object> createJsonHttpMessageConverter() {
MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
jackson2HttpMessageConverter.setObjectMapper(new HibernateAwareObjectMapper());
return jackson2HttpMessageConverter;
}
관련 해결법 전부 안됨.
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonBackReference
@JsonManagedReference
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
spring.jackson.serialization.fail-on-empty-beans=false