纸上得来终觉浅
1.双向多对多:B(Teacher)有多个A(Student),A也有多个B
注意要在一方加上inverse属性,否则一起维护关联关系可能会造成主键冲突:
package roadArchitectWeb;
import java.util.HashSet;
import java.util.Set;
public class Teacher {
private Integer Id;
private String Name;
private String PhoneNum;
private Set<Student> Students = new HashSet<>();
public Set<Student> getStudents() {
return Students;
}
public void setStudents(Set<Student> students) {
Students = students;
}
public Integer getId() {
return Id;
}
public void setId(Integer id) {
Id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getPhoneNum() {
return PhoneNum;
}
public void setPhoneNum(String phoneNum) {
PhoneNum = phoneNum;
}
public Teacher() {
}
@Override
public String toString() {
return "Teacher [Id=" + Id + ", Name=" + Name + ", PhoneNum=" + PhoneNum + ", Students=" + Students + "]";
}
}
package roadArchitectWeb;
import java.util.HashSet;
import java.util.Set;
publi