hibernate一对多,更新主表时删除旧的多方数据加入新的多方数据

xiaoxiao2021-02-28  86

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

转载请注明原文地址: https://www.6miu.com/read-66196.html

最新回复(0)