我一直在寻找好几天,但似乎无法找到答案。
鉴于此多对多(员工/会议)
@Entity
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name="EMPLOYEE_ID")
@GeneratedValue
private Long employeeId;
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name="EMPLOYEE_MEETING",
joinColumns={@JoinColumn(name="EMPLOYEE_ID")},
inverseJoinColumns={@JoinColumn(name="MEETING_ID")})
private Set<Meeting> meetings = new HashSet<Meeting>();
}
@Entity
@Table(name="MEETING")
public class Meeting {
@Id
@Column(name="MEETING_ID")
@GeneratedValue
private Long meetingId;
@ManyToMany(mappedBy="meetings")
private Set<Employee> employees = new HashSet<Employee>();
}
我可以将员工添加到会议中,并显示在employee_meeting表中。
当我获得会议对象并将其删除时,它也会从联接表中消失,但仍保留在员工集中......这是预期的行为吗?
以下是删除会议对象的方法
session.delete(meeting);
transaction.commit();
此时它从桌子上消失了。
谢谢!