我正在尝试与多对多关系的级联,我有两个类Employee和Meeting,它们被映射如下
Employee.java
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "EMPLOYEE_MEETING", joinColumns = {@JoinColumn(name = "EMPLOYEE_ID")}, inverseJoinColumns = {@JoinColumn(name = "MEETING_ID")})
private List<Meeting> meetings = new ArrayList<>();
Meeting.java
@ManyToMany(mappedBy = "meetings", cascade = CascadeType.ALL)
private List<Employee> employees = new ArrayList<>();
使用Insert工作正常,但当我删除单个实体时,如
Employee employee = entityManager.find(Employee.class, 1);
entityManager.getTransaction().begin();
entityManager.remove(employee);
entityManager.getTransaction().commit();
删除与该员工相关的所有会议,然后再删除与会议相关的所有员工。
所以我在这里很困惑如何使用具有多对多关系的级联?