-
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Error attempting to apply AttributeConverter; nested exception is javax.persistence.PersistenceExceptionSpring 2022. 5. 31. 18:45반응형
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Error attempting to apply AttributeConverter; nested exception is javax.persistence.PersistenceException:..
JPA AttributeConverter에서 exception 발생하는 경우입니다.
JPA entity에서 conveter를 만들어서 사용하는 경우에 null 처리가 안되어 있을 때 발생합니다.
public class ExampleEntity { // ..... @Column(name = "ids", columnDefinition = "json") @Convert(converter = CustomConverter.class) private List<Long> ids; }
public class CustomConverter implements AttributeConverter<Object, String> { private static final ObjectMapper om = new ObjectMapper(); @Override public String convertToDatabaseColumn(Object attribute) { if (Objects.isNull(attribute) { // ... null 처리 } try { return om.writeValueAsString(attribute); } catch (JsonProcessingException ex) { //... exception 처리 } } @Override public Object convertToEntityAttribute(String dbData) { if (Objects.isNull(dbData) { // ... null 처리 } try { return om.readValue(dbData, new TypeReference<List<Long>>() {}); } catch (IOException ex) { //... exception 처리 } } }
해결방법
convertToDatabaseColum(), convertToEntityAttributes() 함수에서 받는 paramter Null 처리하는 부분을 추가한다.
반응형'Spring' 카테고리의 다른 글
Spring - @Component, @Service, @Controller 차이 (0) 2022.06.20 Spring - mybatis jdbc 멀티쿼리 설정 (0) 2022.06.16 [Request processing failed; nested exception is java.lang.NullPointerException] with root cause (0) 2022.05.30 Request header is too large 해결방법 (0) 2022.05.30 Spring - ThreadPoolExecutor reject policy 설정 (0) 2022.05.30