我想先删除所有书架和书,然后再删除图书馆
public void deleteLibrary(Long library_id) {
File fileImage = new File("");
Library library = libraryDao.get(library_id);
User user = userDao.get(SecurityUtil.getPricipal());
library.deleteAllLibrarian(roleDao.getRoleByName(RoleName.LIBRARIAN));
library.deleteAllEmployee(roleDao.getRoleByName(RoleName.EMPLOYEE));
for(Shelf s:library.getShelves()) {
library.delete(s);
s.setLibrary(null); //delete shelf // a shelf contain many book
}
libraryDao.delete(library); //delete library
}
删除图书馆 时出现错误,因为尚未删除所有图书。
已删除的对象将通过级联重新保存(从关联中删除已删除的对象):[com.quangdat.entities.Book#7]