我有两个双向课程。是否有必要自己管理两端?例如:将两个对象相互添加,并在删除对象之前同时删除两个引用?
class Customer {
@OneToMany(mappedBy = "customer")
List<Employee> employees;
}
class Employee {
@ManyToOne
Customer customer;
}
Employee emp = new Employee();
Customer customer = new Customer();
customer.getEmployees().add(emp);
emp.setCustomer(customer);
删除时相同(首先清除引用,然后删除对象)。