Reputation: 553
I have two Entity classes which possess many to many uni directional association.Here is my full code. What would be query if I want to fetch list of students which have same course like English ? I have no getter setter of list of student in Courses Entity because I am using unidirectional many to many relationship . Please help me.
@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;
}
Upvotes: 1
Views: 702