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 –