identifier of an instance of .. altered to null ---- hibernate exception
来源:互联网 发布:正在等待网络准备好 编辑:程序博客网 时间:2024/06/05 19:31
identifier of an instance of .. altered to null
是做Hibernate,对一条数据进行复制(新增数据)时遇到的问题
原因:
在SSH框架中,我们常常把事务放在业务逻辑层(Manager),所有业务逻辑完成后才能commit事务,这时候,如果我们从数据库load/get一个对象出来,虽然对它写update方法,但是在提交事务时候,hibernate仍有要把当前对象和session中对象做比较,一旦修改了该对象某个属性,hibernate会自动执行更新操作的。
其实就是我将原来的对象Id由原来的数据【xxxx】改变为null,所以hibernate在保存数据的时候才会报错,hibernate在这里监听到的是属性值改变,是更新而不是保存
我原本是想再原来数据的基础上复制一条和他一样的来,没想到却做成了修改。
解决方法:
不能直接更新已经查到的数据,要new一个对象实例,进行属性复制(BeanUtils.copyProperties(source, dist))
扩展:
如果要复制的实例中,关联到另外一个或几个实例,此时你就要分析是哪个关联到哪个,如果你复制的实例是被关联,那可以不用考虑关联,直接将该关联属性置空。
反之,如果不是被关联,就要考虑关联的问题了
- identifier of an instance of .. altered to null ---- hibernate exception
- identifier of an instance of was altered from to null
- identifier of an instance of was altered from to null
- identifier of an instance ...... altered from ** to **
- org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X
- org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X
- identifier of an instance of com.you.hibernate.model.TStudentInfo was altered from 6 to 7
- org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X
- identifier of an instance ... altered from num1 to num2
- EJB3 Exception:identifier of an instance of net.model.entity.Role was altered from 2 to 0
- Hibernate学习: 异常 identifier of an instance of com.zhssh.vo.TUser was altered from 1 to 1
- 遇到错误 org.hibernate.HibernateException: identifier of an instance of XXX was altered from X to X 将int
- identifier of an instance of XXX was altered from 75
- identifier of an instance of Object is altered from 2 to 5
- 异常:identifier of an instance of cn.ebank.pojo.News was altered from 2 to 2;
- 关于identifier of an instance of Object was altered from 6 to 6异常解决问题
- merge对比引发的identifier of an instance of entity was altered from .. to ..报错
- identifier of an instance was altered from XXXX to XXXX解决
- 排序算法稳定性
- B. Effective Approach
- Eclipse 删除 文件所有空行
- hdwiki
- securecrt 上传下载
- identifier of an instance of .. altered to null ---- hibernate exception
- IOS 4.0支持后台运行
- VDP角色说明--静下来
- 3des加密解密for windows8
- usb的传输和四种传输方式
- Oracle:用户和角色
- Android的View 简单理解和实例
- 博客开始
- eclipse启动参数里设置jvm大小