我有两张桌子,他们有多对一的关系。下面的实体创建一个名为school_id的连接列。问题是项目经理说从不使用连接列而是使用连接表。
我认为当我使用连接表时,它将创建一个像“school_student_relationship”这样的新表,并将存储与该表的关系。为什么我需要使用连接表而不是连接列?是关于表演还是别的什么?
@Entity
@Table(name = "student")
public class Student implements Serializable {
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "school_id")
private School school;
}
@Entity
@Table(name = "school")
public class School implements Serializable {
@Id
@Column(name = "school_id")
private String schoolId;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "school", fetch = FetchType.LAZY)
private List<Student> students= new ArrayList<>();
}