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);