sea*_*est 10 many-to-many ejb jpa properties jointable
我有一个关于在EJB中设计ManyToMany的问题,jointable如何具有属性?
这是一个例子,学生和课程是ManyToMany,每个学生都有很多课程,很多学生选择一门课程.
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我在JoinTable中有一个属性,例如每个学生只有一个课程的分数.如何使用ManyToMany在EJB中创建它?
非常感谢您的关注!
| 归档时间: |
|
| 查看次数: |
25104 次 |
| 最近记录: |