ดังนั้นฉันเจอนี่ปัญหากับกำลังปรับปรุงเป็นสิ่งมีชีวิตแบบหนึ่งใน DB. ในขณะที่ผ่านไปทั้งหมดรายการและกำลังปรับปรุงเดียวที่เจาะจงช่องข้อมูลมันกินไม่ได้แตะต้องเลยด้ฟิลด์เป็นโพรโทคอล aimcomment อย่างที่เป็นผลมาจากการพยากรณ์ฉันมีข้อยกเว้นแล้วตั้งแต่พวกนั้นช่องข้อมูลเป็น @Not-Null
,
ฉันพยายามตามหาคล้ายๆกับปัญหาแต่ไม่สามารถแก้ไขปัญหาของฉัน
บริษัทรายการ:
@Entity
@Table (name = "companies")
@Data
@ToString(exclude = "perfumes")
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Company {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@NotNull
private String name;
@NotNull
@Email(message = "Wrong input. please enter a VALID email address")
private String email;
@NotNull
@Size(min = 4, max = 14, message = "Password range must be between 4 - 14 digits")
private String password;
@NotNull
@Enumerated(EnumType.STRING)
private Country country;
@Singular
@OneToMany(mappedBy = "company", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Perfume> perfumes = new ArrayList<>();
}
ช่องข้อมูลส่วนใหญ่เป็น @NotNull
สำหรับการสร้างอย่างไรก็ตาม,ฉันต้องการจะปรับปรุงรายการ,บางครั้งเดียวที่เจาะจงช่องข้อมูล.
บริการ:
@Override
public String updateCompany(int id, Company company) throws DoesNotExistException {
if(!companyRepository.existsById(id))
{
throw new DoesNotExistException(id);
}
companyRepository.saveAndFlush(company);
return company.getName() + " has been UPDATED";
}
อย่างที่คุณสามารถเห็น ENTITY
ถูกผ่านไปซึ่งทำให้เหลือของแอททริบิวต์ต่างๆที่จะอัตโนมัติโพรโทคอล aimcomment ถ้าไม่ได้ทำการเปลี่ยนแปลง
Controller:
@PutMapping("/updateCompany/{id}")
@ResponseStatus(HttpStatus.ACCEPTED)
public String updateCompany(@PathVariable int id, @RequestBody Company company) throws DoesNotExistException {
return admin.updateCompany(id,company);
}
ยกเว้น:
Validation failed for classes [com.golden.scent.beans.Company] during update time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=password, rootBeanClass=class com.golden.scent.beans.Company, messageTemplate='{javax.validation.constraints.NotNull.message}'}
]
ขอบคุณ