多对多单向-joinTable为空

问题描述

导师和学生之间有很多关系。首先保存该学生。然后,我创建一个新的教师,并尝试将学生添加到教师中的studentList中。然后,我保存(坚持)讲师。讲师坚持不懈,但可接合关节为空。有什么想法吗?

@Entity
@Table(name = "instructor")
@PersistenceContext(unitName = "processEntities")
public class Instructor extends Person {

  private static final long serialVersionUID = 1L;

  @ManyToMany
  @JoinTable(
        name = "instructor_student",joinColumns = @JoinColumn(name = "instructor_id"),inverseJoinColumns = @JoinColumn(name = "student_id")
        )
  private List<Student> students = new ArrayList<Student>();

 public List<Student> getStudents() {
    return students;
 }

 public void setStudents(List<Student> students) {
    this.students = students;
 }  
}

ThesisFirstInstructor.java

@Entity
@Table(name = "thesisfirstinstructor")
@PersistenceContext(unitName = "processEntities")
public class ThesisFirstInstructor extends Instructor {}

Student.java

@Entity
@Table(name = "student")
@PersistenceContext(unitName = "processEntities")
public class Student extends Person {

  private static final long serialVersionUID = 1L;

 private String matrNo;

 public String getMatrNo() {
    return matrNo;
 }

 public void setMatrNo(String matrNo) {
    this.matrNo = matrNo;
 }

BusinessLogic.java(EJB)

{
...
Student currentStudent= studentDAO.findByThmUid(currentStudentThmUid);


ThesisFirstInstructor thesisFirstInstructor = new ThesisFirstInstructor();
thesisFirstInstructor.setFirstName(thesisFirstInstructorCamundaUser.getFirstName());
thesisFirstInstructor.setLastName(thesisFirstInstructorCamundaUser.getLastName());
thesisFirstInstructor.setThmUid(thesisFirstInstructorThmUid);

List<Student> studentList = thesisFirstInstructor.getStudents();
studentList.add(currentStudent);
        
thesisFirstInstructorDAO.persist(thesisFirstInstructor);

}

The thesisFirstInstructor is persisted. But the jointable stays empty.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)