在双向关系中,我们可以从任何一方进行保存吗?
@Entity
public class Department {
@OneToMany
private Collection<employee> employees;
...
}
@Entity
public class Employee {
@ManyToOne
private Department department;
...
}
我们可以决定吗
departement.setEmployee(employees)
departmentDao.save(departement);
和
employee.setDepartment(department);
employeeDao.save(employee);
答案 0 :(得分:1)
我认为这取决于您在关系中使用的级联类型(@ManyToOne,@ OneToMany等)以及您放置它的实体。
https://docs.oracle.com/javaee/6/api/javax/persistence/CascadeType.html