我有以下关系
Class UserAccount{
@OneToMany(mappedBy = "firstSharedBy")
private List<Images> imagesFirstShared;
}
Class Images{
@ManyToOne
@JoinColumn
private UserAccount firstSharedBy;
}
我想删除一个 UserAccount 实例。所以我这样做。
userAccount.getImagesFirstShared().clear();
entityManager.remove(userAccount);
但它会引发以下异常
Cannot delete or update a parent row: a foreign key constraint fails (`testdb`.`Images`, CONSTRAINT `FK201C4A25D4C117` FOREIGN KEY (`firstSharedBy_USER_NAME`) REFERENCES `USERACCOUNT` (`USER_NAME`))
有任何线索的人吗?提前致谢