문제

I'm using play-framework 2.2.1 with Ebean. I have a manyToMany relantionship between Student and SchoolClass.

Inside a transaction, when a schoolClass is created, added to Student and saved, the respective bridge table is not filled.

@Entity
public class Student extends Model {
    ...

    @ManyToMany(cascade = CascadeType.ALL)
    public List<SchoolClass> schoolClasses = new ArrayList<SchoolClass>();
}

@Entity
public class SchoolClass extends Model {
     ...

     @ManyToMany(mappedBy = "schoolClasses")
     public List<Student> students = new ArrayList<Student>();
}

Code:

try {
    Ebean.beginTransaction();

    ...
    Student student = new Student();
    student.schoolClasses.add(schoolClass);
    student.save();

    Ebean.commitTransaction();
} finally {
    Ebean.endTransaction();
}

Any ideas?

도움이 되었습니까?

해결책

I have once experienced a similar problem, could you try it like the following:

List<SchoolClass> classes = new ArrayList<SchoolClass>();
classes.add(schoolClass);
student.schoolClasses.addAll(classes);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top