0

我有两个双向课程。有必要总是自己管理两端吗?例如:将两个对象相互添加,并在对象删除之前相互删除两个引用?

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);

删除时相同(首先清除引用,然后删除对象)。

4

0 回答 0