JPA一对多关系“父键不能为空”的问题
父母 - 登记处
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
@JoinColumn(name = "registry_id", nullable = false , insertable = true)
@PrivateOwned
public List<ContactData> getContactDataList() {
return contactDataList;
}
child - ContactData
@Column(name = "registry_id", length = 20)
public BigInteger getRegistryId() {
return registryId;
}
public void setRegistryId(BigInteger registryId) {
this.registryId = registryId;
}
子save中的错误会抛出父id不能为null
无法改变数据库端
问题父键不能为空,因为您正在保存没有父/主表引用的子/依赖表数据。
解:
希望这能解决你的问题。
谢谢 :)