Определение:Hibernate: удаленный объект будет вновь спасена каскад
@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 Nope. Проблема, поскольку вы можете видеть, что у меня нет списка для удаления объекта из ... Я заполняю объект из db и выполняю команду delete. – nKognito
это может быть связано с тем, что файл AirlineSupplierProductFile по-прежнему ссылается на файл-объект при вызове delete (file). Попробуйте скопировать объект файла в другой объект AirlineSupplierProductFile и использовать его для удаления из сеанса. Что-то вроде delete (copied_file_obj); –