删除客户会导致以下异常
CustomerDTO customerDTO = customerDAO.findById(9);
customerDAO.remove(customerDTO);
"无法删除或更新父行:外键约束失败"
我在关系中使用 CascadeType.ALL 和 orphanRemoval = true ,但它无效。
@Entity
@Table(name = "CUSTOMER")
public class CustomerDTO implements Serializable {
@Column(name = "cust_first_name")
private String firstName;
@Column(name = "cust_last_name")
private String lastName;
@OneToMany(mappedBy="customerDTO", fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
private List<SystemContractDTO> lstDeviceContractsDTO;
}
@Entity
@Table(name = "SYSTEM_CONTRACT")
public class SystemContractDTO implements Serializable {
@ManyToOne(optional=false, cascade=CascadeType.DETACH)
@JoinColumn(name="customer_id")
private CustomerDTO customerDTO;
}