hibernate错误:org.hibernate.NonUniqueObjectException: a different object with the same identifier valu

来源:互联网 发布:移动网络哪家 编辑:程序博客网 时间:2024/05/21 11:13
if (StringUtil.isNotEmpty(supplyCatalog.getId())) {message = "更新成功";SupplyCatalogEntity t = supplyCatalogService.get(SupplyCatalogEntity.class, supplyCatalog.getId());// 1//org.hibernate.Session session = systemService.getSession();//session.clear();try {if (StringUtil.isNotEmpty(request.getParameter("warehouseId0"))) {t.setWarehouseId(Integer.valueOf(request.getParameter("warehouseId0")));}t.setLatestTime(new Date());t.setLatestUser(this.getSysUserName(request));MyBeanUtils.copyBeanNotNull2Bean(supplyCatalog, t);if (t.getParentCatalog() != null && t.getParentCatalog().getId() == null) {t.setParentCatalog(null);}// 2//SupplyCatalogEntity parent = systemService.get(SupplyCatalogEntity.class, t.getParentCatalog().getId());//t.setParentCatalog(parent);supplyCatalogService.saveOrUpdate(t);systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);} catch (Exception e) {e.printStackTrace();}}


一开始报错:org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

然后添加了“1”处被注释的代码,这样把session中冲突的实体清除了,不报错了。

但是看数据库,发现父节点的数据记录被清空了,只留了一个id。

之后添加了“2”处的代码,就能存住父节点信息了。






0 0