hibernate之ManyToMany

一个老师有多个学生,同样一个学生有多个老师,配置如下:

@ManyToMany(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST,CascadeType.MERGE})
@JoinTable(name = "teacher_student", joinColumns = @JoinColumn(name = "teacher_id"), inverseJoinColumns = @JoinColumn(name = "student_id"))
@OrderBy("num DESC")
private Set<Student> students = new HashSet<Student>();

@ManyToMany(fetch=FetchType.LAZY,mappedBy="students")
private Set<Teacher> teachers = new HashSet<Teacher>();
 

你可能感兴趣的:(Hibernate)