我有商家和地址表。一个商家可以有多个地址,一个地址有一个商家(一对多关系)。当用地址添加商家价值时,我收到此错误。如何解决此错误?这是错误。
{
"timestamp": 1554878673504,
"status": 500,
"error": "Internal Server Error",
"message": "could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement",
"path": "/merchant-service/save-merchant"
}
这是我的输入值:
{
"idNo": null,
"idType": null,
"emailId": "email@gmail.com",
"name": null,
"status": true,
"createdBy": null,
"modifiedBy": null,
"createdDate": null,
"modifiedDate": null,
"contacts": [
{"contactNo": "0766601122"}],
"addresses": [
{"line1": "manipay"},
{"line1": "suthumalai"}
]
}
这是我在商家模型中的代码:
@OneToMany(fetch = FetchType.LAZY,cascade = {CascadeType.ALL}, mappedBy = "merchant")
private Set<Address> addresses = new HashSet<Address>(
0);
这是我在地址模型中的代码:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "merchant_id", nullable = false)
// @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
// @Getter(onMethod = @__( @JsonIgnore))
// @Setter
private Merchant merchant;
这是我的服务:
public Merchant saveMerchant(Merchant merchant) {
merchant = merchantRepository.save(merchant);
return merchant;
}
森栏
POPMUISE
相关分类