@OneToMany(fetch = FetchType.EAGER)
@Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.ALL})
private List<Student> studentList; //集合列表
在service層中。更新主表前,先獲取舊的集合子對象,然後在更新完主表後,對舊的集合對象進行刪除
Classroom classroom=classroomDao.findById(id);
List<student> tempList=classroom.getStudentList();
classroom.setStudnetList(myNewStudnetList);
if(tempList!=null)
for(Student item: tempList)
{
studentDao.remove(item);
}