Hibernate更新数据报错:a different object with the same identifier value was already associated with the session: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001]
使用hibernate更新数据时,报错
Struts has detected an unhandled exception: Messages:
a different object with the same identifier value was already associated with the session: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001]
a different object with the same identifier value was already associated with the session: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001];
nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
[com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001]
代码如下:
/**
* @Name saveElecCommonMsg
* @Description: 保存运行监控表的数据
* @author kj
* @version: V1.00
* @create Date: 2017-05-21
* @Parameters: saveElecCommonMsg:VO对象
* @return 无
* 此处需要保存或者更新,要加上事务
*/
@Override
@Transactional(readOnly=false)
public void saveElecCommonMsg(ElecCommonMsg elecCommonMsg) {
// 1.查询数据库运行监控表的数据,返回List,用来判断数据是否存在
List<ElecCommonMsg> list = elecCommonMsgDao.findCollectionByConditionNoPage("", null, null);
//存在就更新
if(list != null && list.size() > ){ ElecCommonMsg cmg = list.get(0);
elecCommonMsg.setComID(cmg.getComID());
elecCommonMsg.setCreateDate(new Date());
elecCommonMsgDao.update(elecCommonMsg);
}
}
原因是:使用update更新(Session中不允许出现2个相同的OID),所以此处改用 使用快照进行更新
/**
* @Name saveElecCommonMsg
* @Description: 保存运行监控表的数据
* @author kj
* @version: V1.00
* @create Date: 2017-05-21
* @Parameters: saveElecCommonMsg:VO对象
* @return 无
* 此处需要保存或者更新,要加上事务
*/
@Override
@Transactional(readOnly=false)
public void saveElecCommonMsg(ElecCommonMsg elecCommonMsg) {
// 1.查询数据库运行监控表的数据,返回List,用来判断数据是否存在
List<ElecCommonMsg> list = elecCommonMsgDao.findCollectionByConditionNoPage("", null, null);
//存在就更新
if(list != null && list.size() > 0 ){
ElecCommonMsg ecg = list.get();
ecg.setStationRun(elecCommonMsg.getStationRun());
ecg.setDevRun(elecCommonMsg.getDevRun());
ecg.setCreateDate(new Date());
}else{//否则就保存
elecCommonMsg.setCreateDate(new Date());
elecCommonMsgDao.save(elecCommonMsg);
}
}
Hibernate更新数据报错:a different object with the same identifier value was already associated with the session: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001]的更多相关文章
- a different object with the same identifier value was already associated with the session:
hibernate操作: 实例化两个model类,更新时会提示 a different object with the same identifier value was already assoc ...
- hibernate中一种导致a different object with the same identifier value was already associated with the session错误方式及解决方法
先将自己出现错误的全部代码都贴出来: hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> ...
- Hibernate Error: a different object with the same identifier value was already associated with the session
在执行Hibernate的Update操作时,报错:a different object with the same identifier value was already associated w ...
- Exception 06 : org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session :
异常名称: org.hibernate.NonUniqueObjectException: A different object with the same identifier value was ...
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
保存实体异常 https://blog.csdn.net/zzzz3621/article/details/9776539 org.hibernate.NonUniqueObjectException ...
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session异常解决办法
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread ...
- hibernate 异常a different object with the same identifier value was already associated with the session
在使用hibernate的时候发现了一个问题,记录一下解决方案. 前提开启了事务和事务间并无commit,进行两次save,第二次的时候爆出下面的异常a different object with t ...
- [转]解决a different object with the same identifier value was already associated with the session错误
1.a different object with the same identifier value was already associated with the session. 错误原因:在h ...
- a different object with the same identifier value was already associated with the session:错误;
当出现a different object with the same identifier value was already associated with thesession时,一般是因为在h ...
随机推荐
- 数据流图(DFD)画法
数据流图(DFD)画法要求 一.数据流图(DFD) 1.数据流图的基本符号 数据流图由四种基本符号组成,见图5-4-1所示. 图5-4-1 数据流图的基本符号 例:图5-4-2是一个简单的数据流图, ...
- Experience on Namenode backup and restore --- checkpoint
Hadoop version: Hadoop 2.2.0.2.0.6.0-0009 Well, We can do this by building Secondary Namenode, Check ...
- 在windows中使用Navicat连接Linux虚拟机中的mysql数据库
今天想用navicat远程连接虚拟机中的MySQL数据库,一直连不上,在网上搜索了一下,发现原因是MySQL对远程用户登陆的授权问题.这里说一下我的解决方法.(本人小白) 首先,我用navicat去远 ...
- jquery ajax 提交form表单 以及django后台接受
HTML <form id="project_file_upload" enctype="multipart/form-data" > <di ...
- java:常用的两种设计模式(单例模式和工厂模式)
一.单例模式:即一个类由始至终只有一个实例.有两种实现方式(1)定义一个类,它的构造方法是私有的,有一个私有的静态的该类的变量在初始化的时候就实例化,通过一个公有的静态的方法获取该对象.Java代码 ...
- 跟着百度学习php之ThinkPHP的运行流程-1
我在index\Lib\Action\目录下新建了一个ShowAction.class.php文件.ps:该目录是控制器的目录. 然后这个文件中继承了action这个类.代码如下: <?php ...
- vsftpd 服务移植出现 500 oops : socket 解决
一开始, 在vsftpd 打印的错误是 500 oops : socket 在 vsftpd 源码里面找到 buildroot-2016.05/output/build/vsftpd-3.0.3/sy ...
- netctl
netctl is a CLI-based tool used to configure and manage network connections via profiles. It is a na ...
- 绝对详细!Nginx基本配置、性能优化指南
大多数的Nginx安装指南告诉你如下基础知识——通过apt-get安装,修改这里或那里的几行配置,好了,你已经有了一个Web服务器了!而且,在大多数情况下,一个常规安装的nginx对你的网站来说已经能 ...
- Javascript 你不知道的事
NaN表示一个不能产生正常结果的运算结果.它不等于任何值,包括它自己.可以用isNaN(number)来检测. 同Java中的字符串一样,JS中的字符串是不可变的.也就是说一旦字符串被创建,就无法改变 ...