我正在尝试删除 Patient 实体而不删除关联的 OutboundMessage 实体,因为我想将它们保留在数据库中以用于报告/历史目的。这是相关代码:
患者实体
@OneToMany (mappedBy="patient", fetch = FetchType.EAGER,orphanRemoval = false)
public Set<OutboundMessage> getOutboundMessages()
{
return outboundMessages;
}
OutboundMessage 实体
@ManyToOne (fetch=FetchType.EAGER)
@JoinColumn(name = "id_patient")
public Patient getPatient()
{
return patient;
}
当我在患者端设置级联类型时,记录被删除,这不是我想要的。当尝试如上面的代码所示(没有级联类型)时,我得到以下异常:
The DELETE statement conflicted with the REFERENCE constraint "FKqjpga9w6wp3qk26ox9pg252d9". The conflict occurred in database "MDHIS", table "dbo.tblOutboundMessage", column 'id_patient'.
拥有实体需要哪些设置才能允许删除而不级联到子实体并且不清理孤立记录?
谢谢!