JPA ManyToMany,JoinTable如何拥有属性?

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中创建它?
非常感谢您的关注!

Yog*_*ogu 4

这是不可能的,你不能将财产添加到关系中。如果您需要访问连接表中的属性,那么该属性属于某个实体,因此您需要第三个实体。