헤르메스 LIFE

[JpaSystemException] Resolved [org.springframework.orm.jpa.JpaSystemException: Null value was assigned to a property 본문

Exception

[JpaSystemException] Resolved [org.springframework.orm.jpa.JpaSystemException: Null value was assigned to a property

헤르메스의날개 2023. 3. 19. 00:09
728x90

개발환경

Spring Boot 2.7.9

H2 2.1.214

p6spy 1.8.1

slf4j 1.7.36

swagger2 2.6.1

lombok

devtools

postgresql

JPA


아래와 같은 오류가 발생했습니다.


INFO 23-03-18 11:39:785[http-nio-9090-exec-1] octopus.advice.ExceptionAdvice.dataAccessException[72]: - [ExceptionAdvice >> dataAccessException] result :: {errCode=-1, errMsg=Null value was assigned to a property [class octopus.entity.TCodeD.numOpt1] of primitive type setter of octopus.entity.TCodeD.numOpt1; nested exception is org.hibernate.PropertyAccessException: Null value was assigned to a property [class octopus.entity.TCodeD.numOpt1] of primitive type setter of octopus.entity.TCodeD.numOpt1}
WARN 23-03-18 11:39:787[http-nio-9090-exec-1] org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.logException[208]: - Resolved [org.springframework.orm.jpa.JpaSystemException: Null value was assigned to a property [class octopus.entity.TCodeD.numOpt1] of primitive type setter of octopus.entity.TCodeD.numOpt1; nested exception is org.hibernate.PropertyAccessException: Null value was assigned to a property [class octopus.entity.TCodeD.numOpt1] of primitive type setter of octopus.entity.TCodeD.numOpt1]

----------------------------------------------------------------------------------------------------------------------------
발생 원인은 DB에서 null값이 들어갈 수 있는 컬럼의 속성 타입이 자바에서 Primitive Type으로 되어 있기 때문입니다.
Primitive Type 이란 boolean, byte, short, int, long, float, double, char 등의 Type을 말합니다.
Primitive Type에 은 null값을 담을 수 없습니다.
----------------------------------------------------------------------------------------------------------------------------

해결책방법은 아래와 같습니다.
TCodeD,java 파일의 아래와 같은 소스를

/**
 * 숫자옵션명#1
 */
 @Column
 private int numOpt1;


아래와 같이 변경합니다.

/**
 * 숫자옵션명#1
 */
 @Column
 private Integer numOpt1;
728x90