0
我有一個僱員對象和地址對象的視圖實體對象。一個視圖有一個員工名單。員工有地址列表。我想刪除該員工。我收到了一個抱怨刪除視圖的約束。該觀點應該保留,但觀點與員工之間的關係應該消失。地址也應該沒有了。 誰能告訴我如何設置我的JPA來處理這種情況?或者我應該以編程方式進行。 (先查看所有視圖,然後從視圖中刪除員工)。當孩子被刪除時,JPA是否可以處理刪除父對象?
View {
@OneToMany(targetEntity = Employee.class, orphanRemoval = true)
@JoinTable(name = "View_Employee")
protected List<Employee> employees;
}
Employee {
@CascadeOnDelete
@OneToMany(targetEntity = Address.class, orphanRemoval = true,fetch=FetchType.EAGER)
@JoinTable(name = "Employee_Address")
@XmlElement(required = true)
@OrderColumn
protected List<Address> address;
}
Address{
nothing of interest, no ties to view or employee
}
請張貼異常消息。 另外檢查關於orphanRemoval和Cascade.DELETE的這個: http://stackoverflow.com/questions/17708687/jpa-cascade-all-causing-integrity-constraint/17713417#17713417 –