μ΄λ² ν¬μ€ν μ κ²½μ° μ¬μν μ€μμμ λμ¨ .. κ·Έλ° μλ¬μ΄λ€.
JPA ν μ€νΈλ₯Ό νλ€κ° λμ¨ μλ¬μΈλ° not-null proerty error μ΄λ€.
not-null property references a null or transient value
μλ° κ°μ²΄μ λ°μ΄ν°κ° null λ‘ λ€μ΄κ° λ λλ μλ¬μ΄λ€
not-null property references a null or transient value : io.gonzo.jpa.app.domain.basic.Product.price; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value : io.gonzo.jpa.app.domain.basic.Product.price
org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value : io.gonzo.jpa.app.domain.basic.Product.price; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value : io.gonzo.jpa.app.domain.basic.Product.price
λλ―Έν μ΄ν°λ₯Ό λ£μ΄μ£Όλ λ‘μ§μ΄λ€. νμ§λ§ 무μΈκ° λΉ μ§λ― νμλ€..
ProductDTO dto = ProductDTO.builder()
.type("ING")
.name("test....")
.productType(new ProductType("test..."))
.img("project.jpg")
.build();
repository.save(dto.toEntity());
dto μμ λλ―Έλ°μ΄ν°λ₯Ό μ£Όμ ν΄μ€λ null λ‘ λ€μ΄κ°κ³ μμλ€.
ProductDTO dto = ProductDTO.builder()
.type("ING")
.name("test....")
.price(new BigDecimal(0))
.productType(new ProductType("test..."))
.img("project.jpg")
.build();
repository.save(dto.toEntity());
μλ° κ°μ²΄μμ nullable μμ±μ false λ‘ μ£Όμλ€...
false λΌλ κ²μ null μ νμ©μ νμ§ μλλ€λ κ²μΈλ° ..
DTOμ ν μ€νΈλ‘ λλ―Έλ₯Ό μ£Όμ ν λ λͺ¨λ₯΄κ³ κΉλ¨Ήμλκ² κ°λ€...
@Entity
@NoArgsConstructor
@Table(name = "PRODUCT")
public class Product extends DomainEntity {
@Column(name = "TYPE" , nullable = false)
private String type;
@Column(name = "NAME" , nullable = false)
private String name;
@Column(name = "PRICE" , nullable = false)
private BigDecimal price;
@Column(name = "IMG")
private String img;
@ManyToOne
private ProductType productType = null;
@Builder
public Product(String type, String name, BigDecimal price, String img, ProductType productType) {
this.type = type;
this.name = name;
this.price = price;
this.img = img;
this.productType = productType;
}
}