如何自动化双向类对象?

时间:2013-10-14 15:54:00

标签: java database hibernate java-ee

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

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

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

0 个答案:

没有答案