challnum 2022. 9. 9. 19:50
에러 상황

Postman에서 아래의 값을 전송하였을때 에러가 발생하게되었다.

{
    "bookName" : "1",
    "extinction" : true,
    "isbn" : "1",
    "bookpage" : 1,
    "age" : 1,
    "price" : 1,
    "currency" : 1,
    "author" : "1"
}

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception 
[Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value : 
com.example.assignment.Domain.Book.bookName; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value : 
com.example.assignment.Domain.Book.bookName] with root cause
원인 분석
  1. 의존성이 주입되었는가
  2. 쿼리에 맞게 값들이 들어가고 있는가
처리 과정
  1. 모든 부분에 의존성은 주입되었다.
  2. 그렇다면 값이 제대로 들어가고 있지 않은 것이었기에 디버깅을 통한 값을 확인해보자 아래와 같이 bookname의 값이 null로 들어가는 것을 볼 수 있었다.

 

Postman에서 보내는 data의 컬럼명이 달랐기에 발생한 오류이며 대문자를 소문자로 바꿔주니 값이 정확하게 들어가는 것을 볼 수 있었다.

{
    "bookname" : "1",
    "extinction" : true,
    "isbn" : "1",
    "bookpage" : 1,
    "age" : 1,
    "price" : 1,
    "currency" : 1,
    "author" : "1"
}