@ManyToMany

维护端注解

@ManyToMany (cascade = CascadeType.REFRESH)

@JoinTable (//关联表

                   name =  "student_teacher" , //关联表名

                   inverseJoinColumns =  @JoinColumn (name =  "teacher_id" ),//被维护端外键

                   joinColumns =  @JoinColumn (name =  "student_id" ))//维护端外键

被维护端注解

@ManyToMany(

                   cascade = CascadeType.REFRESH,

                   mappedBy = "teachers",//通过维护端的属性关联

                   fetch = FetchType.LAZY)

关系维护端删除时,如果中间表存在些纪录的关联信息,则会删除该关联信息;

关系被维护端删除时,如果中间表存在些纪录的关联信息,则会删除失败 .

你可能感兴趣的:(manytomany)