JPA。删除父原因Foreigconstraint违规例外

时间:2015-07-03 15:14:04

标签: java jpa

删除客户会导致以下异常

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;

}

0 个答案:

没有答案