hibernate异常:a different object with the same identifier value was already associated
来源:互联网 发布:ajax json 解析 编辑:程序博客网 时间:2024/06/06 00:30
a different object with the same identifier value was already associated with
最近在工作中遇到这样一个异常,异常的原因很容易找到,就是看怎么去解决这个异常了 。
最近在工作中遇到这样一个异常,异常的原因很容易找到,就是看怎么去解决这个异常了 。
原因:正常情况一般调用hiberate端方法进行数据库操作时,是直接调用 getHibernateTemplate().update(user);,但在hibernate中同一个session里面有了两个相同标识但是是 不同实体时就会出现如标题的错误,
自己尝试用了网上搜索到的好多方法都不能解决。最后自己找到了两种解决方案:cleaning cloth
我用的是hibernate3.0。
方案一:在写完要一个完整的操作之后,比如,delete操作,调用this.getHibernateTemplate().evict(object),这样就可以把多余的对象给清除掉了。然后再执行需要的操作,如saveOrUpdate。
方案二:同样是在一个完整的操作之后,比如,delete操作,然后同时调用
this.getHibernateTemplate().flush();this.getHibernateTemplate().clear(); 来强迫执行,然后再执行需要的操作,如saveOrUpdate。(注意,这种方法要同时执行这两个方法,单独执行一个都无法达到预期目的)。toothpaste
网上搜到的用clear()方法,merge()方法,或者refresh()方法,在我这里尝试了一下都不行。
这是自己在工作中发现并解决的问题,希望大家多给点指点
我用的是hibernate3.0。
方案一:在写完要一个完整的操作之后,比如,delete操作,调用this.getHibernateTemplate().evict(object),这样就可以把多余的对象给清除掉了。然后再执行需要的操作,如saveOrUpdate。
方案二:同样是在一个完整的操作之后,比如,delete操作,然后同时调用
this.getHibernateTemplate().flush();this.getHibernateTemplate().clear(); 来强迫执行,然后再执行需要的操作,如saveOrUpdate。(注意,这种方法要同时执行这两个方法,单独执行一个都无法达到预期目的)。toothpaste
网上搜到的用clear()方法,merge()方法,或者refresh()方法,在我这里尝试了一下都不行。
这是自己在工作中发现并解决的问题,希望大家多给点指点
转载地址: http://blog.sina.com.cn/s/blog_4b5bc01101016nii.html
0 0
- Hibernate异常: a different object with the same identifier value was already associated with the sessi
- hibernate异常:a different object with the same identifier value was already associated
- a different object with the same identifier value was already associated with the session异常解决办法
- Hibernate Exception: a different object with the same identifier value was already associated with the session
- Hibernate更新a different object with the same identifier value was already associated with the session
- [Hibernate]a different object with the same identifier value was already associated with the session
- Hibernate错误:a different object with the same identifier value was already associated with the sessio
- Hibernate:a different object with the same identifier value was already associated with the session
- hibernate a different object with the same identifier value was already associated with the session
- Hibernate :A different object with the same identifier value was already associated with the session
- hibernate:a different object with the same identifier value was already associated with the session
- 开发中遇到的hibernate异常:a different object with the same identifier value was already associated with the
- a different object with the same identifier value was already associated with异常解决
- a different object with the same identifier value was already associated withthe session异常解决方案
- a different object with the same identifier value was already associated withthe session异常解决方案
- 异常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 already associated with the sessio
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the sessio
- 设计模式之工厂模式
- reveal 1.6.3 本机破解及使用
- Linux进程间通信
- sqlsever 与 Java 数据类型的对应
- iOS App 唤醒另一个App
- hibernate异常:a different object with the same identifier value was already associated
- ARM编译中的RO、RW和ZI DATA区段
- 源码分析 -- 异步消息处理机制
- 使用UGUI制作NGUI的UI Key Navigation
- 【51Nod 1246】罐子和硬币
- caffe的solverstate的使用
- 程序员最害怕的5件事 你中招了吗?
- matplotlib--Legend
- 欢迎使用CSDN-markdown编辑器