EJB での ManyToMany の設計について質問があります。どのようにしてジョイント可能オブジェクトにプロパティを持たせることができますか?
例を次に示します。学生とコースは ManyToMany で、すべての学生は多くのコースを持ち、多くの学生が 1 つのコースを選択します。
@Entity
public class Student implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
String name;
private Collection<Course> courses;
@ManyToMany(mappedBy = "students",cascade=CascadeType.ALL)
public Collection<Course> getCourses() {
return this.courses;
}
public void setCourses(Collection<Course> courses) {
this.courses = courses;
}
}
@Entity
public class Course implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
String name;
private Collection<Student> students;
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(name = "Student_Course",
joinColumns = {@JoinColumn(name = "Course_ID", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "Student_ID", referencedColumnName = "id")})
public Collection<Student> getStudents() {
return this.students;
}
public void setStudents(Collection<Student> students) {
this.students = students;
}
}
ただし、JoinTable にプロパティがある場合、たとえば、各学生は 1 つのコースに対して 1 つのスコアを持っています。ManyToMany を使用して EJB で作成するにはどうすればよいですか?
ご清聴ありがとうございました!