1
@OneToMany(mappedBy = "product", fetch = FetchType.LAZY, cascade = { CascadeType.ALL }, orphanRemoval = true)
@Where(clause = "ownerType=22")
private List<AirlineSupplierProductFile> files = new ArrayList<AirlineSupplierProductFile>(0);
代码:
@RequestMapping(value = "/remove-product-file", method = RequestMethod.GET, headers = BaseController.AJAX_HEADER)
public @ResponseBody JSONResponse removeProductFile(@RequestParam(value = "id", required = true) Long id,
@RequestParam(value = "product", required = true) Long productId,
@CurrentUser UserDetailsExtended currentUser) {
JSONResponse json = new JSONResponse();
try {
AirlineSupplierProductFile file = (AirlineSupplierProductFile) fileStorageService.get2(id, OwnerType.AirlinesSupplierProduct);
if (file.getProduct() == null || file.getProduct().getId() == productId)
fileStorageService.delete(file);
}
catch (Exception e) {
json.setData(I18n.getString("errors.common.unexepected"));
json.setCode(AjaxError.Undefined);
log(e, currentUser.getUsername());
}
return json;
}
其中fileStorageService.delete(file)
是:
@Transactional
public void delete(IFileStorageFile object) {
Session session = SessionFactoryUtils.getSession(sessionFactory, false);
session.delete(object);
}
问题:失败deleted object would be re-saved by cascade
。
问题:为什么?
谢谢
这能否帮助? http://stackoverflow.com/questions/15820491/org-hibernate-objectdeletedexception-deleted-object-would-be-re-saved-by-cascad –
@JtheRocker没有。这个问题,你可以看到我没有任何列表来删除对象...我从db中填充对象并执行删除命令。 – nKognito
这可能是由于AirlineSupplierProductFile文件仍然在调用delete(file)时引用了文件对象。尝试将文件对象复制到不同的AirlineSupplierProductFile对象,并使用它从session中删除。像delete(copied_file_obj); –