1
我有兩個實體類擁有多對多的單向關聯。這裏是我的完整代碼。如果我想要提取像英語一樣的課程的學生名單,會出現什麼問題?我在課程實體中沒有學生名單的getter setter,因爲我使用的是單向多對多關係。請幫幫我。如何使用標準獲取列表多對多的冬眠單向關聯?
@Entity
@Table(name = "course")
public class Courses {
@Id
@Column(name = "sid")
@GeneratedValue(generator = "uuid")
private String id;
//other getters setters
}
@Entity
@Table(name = "student")
public class Student {
@Id
@Column(name = "sid")
@GeneratedValue(generator = "uuid")
private String id;
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "stu_cou", joinColumns = {@JoinColumn(name = "sid", nullable = false)}, inverseJoinColumns = { @JoinColumn(name = "cid", nullable = true) })
private List<Courses> courses;
}
還有其他想法嗎? – pankaj