您的位置:首页 > 移动开发 > Objective-C

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

2014-05-20 15:57 781 查看
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”处的代码,就能存住父节点信息了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐