티스토리 뷰
스펙도 쌓니
Oh ... not-null property references a null or transient value 해결 Resolve
군포망나니 2025. 1. 28. 17:43반응형
에러 해결하기 위해 4-50분 소요////
@ Article.java
package command.pyramid.Domain;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
public class Article {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true,updatable = false)
private Long id;
@Column(name="title", nullable = false)
private String title;
@Column(name = "content", nullable = false)
private String content;
@Builder
public Article(String title, String content) {
this.title = title;
this.content = content;
}
}
title 과 content 에 NotNull 을 설정했기 때문에 당연히 Null 값이 들어가면 오류가 뜰 것이다.
이를 신경써가며 postman 으로 title 과 content 를 잘 집어넣었다
흠... 그래서
not-null property references a null or transient value: command.pyramid.Domain.Article.content
이러한 에러메시지가 떴다.
content 도 잘 넣었는데 ?? 왜ㅑ ...
그래서 content 에 Null 값을 허용하고 돌렸더니
not-null property references a null or transient value: command.pyramid.Domain.Article.title
이게 뜸 ㅋㅋ
H2 도 연결이 잘 되어있음.
흠 ...
구글링 실패 이슈로 나의 필살기 ChatGPT 에게 여쭤봄 ㅋㅋ.
@RequiredArgsConstructor
public class AddArticleRequest {
private final String title;
private final String content;
public Article toEntity() {
return Article.builder()
.title(title)
.content(content)
.build();
}
}
GPT : @RequiredArgsConstructor를 사용하려면 필드에 final을 추가하세요. 그러나 이렇게 하면 값을 반드시 생성자에서 초기화해야 하므로 DTO로 사용하기에는 불편할 수 있습니다.
오늘도 고마워...
이제 진짜 개발자는 필요가 없는 걸까...?
반응형
'스펙도 쌓니' 카테고리의 다른 글
[클라우드] 배포 실패 Log 분석 -> AWS 로그 파일 다운로드 먼저! (0) | 2025.02.08 |
---|---|
[SpringBoot] reason: Incompatible parameter types in method reference expression 해결 Resolve (0) | 2025.01.28 |
H2 - Spring Boot Configuration (1) | 2025.01.28 |
테스트 코드는 무수한 반복 반복 반복 을 견뎌라!! (0) | 2025.01.27 |
RestController 와 Controller 를 이용하기 위해서는 어떻게 할까? (0) | 2025.01.27 |