`

Hibernate 疑难异常及处理 a different object with the same identifier value was already

 
阅读更多

错误原因:在hibernate中同一个session里面有了两个相同标识但是是不同实体。

解决方法一:session.clean()
PS:如果在clean操作后面又进行了saveOrUpdate(object)等改变数据状态的操作,有可能会报出"Found two representations of same collection"异常。

解决方法二:session.refresh(object)
PS:当object不是数据库中已有数据的对象的时候,不能使用session.refresh(object)因为该方法是从hibernate的session中去重新取object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下。

解决方法三:session.merge(object)
PS:Hibernate里面自带的方法,推荐使用。

分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    hibernate常见异常

    a different object with the same identifier value was already associated with the session 是一种常见的异常,通常是由于在 Hibernate 中同一个 session 里面有了两个相同标识但是是不同实体所致。解决方案有...

    hibernate常见问题及处理.doc

    5. `a different object with the same identifier value was already associated with the session` 这个异常表明在同一个Hibernate Session中存在两个具有相同标识但实际是不同对象的情况。处理方法有: - 使用`...

    The Digital Object Identifier initiative: metadata implications

    数字对象标识符(Digital Object Identifier,简称DOI)是一种持久性标识符,用于唯一地标识数字资源,如学术文章、数据集等。DOI系统由国际DOI基金会管理,并在出版界广泛采用。随着数字资源的增加以及对资源描述的...

    计算机网络第六版答案

    In these systems, packets are transmitted over the same wireless infrastructure used for cellular telephony, with the base station thus being managed by a telecommunications provider. This provides ...

    Hibernate Tutorial 03 (Object Identifier).pdf

    在本教程中,我们将深入探讨Hibernate框架中的一个核心概念——对象标识符(Object Identifier)。通过本篇教程的学习,您将了解到对象标识符在Hibernate中的重要性以及如何正确地为持久化对象设置标识符。此外,我们...

    hibernate常见错误解决方案

    **Different Object with Same Identifier Value** **异常描述:** 此异常表示同一个Session中存在具有相同标识符的不同对象实例。 **解决方法:** - 使用`session.clear()`清除Session缓存。 - 调用`session....

    S7A驱动720版本

    - When the signal conditioning function "S&M" was used for a byte value, the driver wrote wrong values to the PLC. Build 223 : New Functions: - The number of supported NetLinks has been ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: The value of some string flex-properties that began with a parenthese or curly bracket had no apostrophe at the end; that caused an error when reading. (fixed TPropList.SavePropValue for the ...

    Hibernate映射导致的几个异常

    标题与描述概述的知识点主要集中在Hibernate映射过程中可能遇到的各种异常情况,这涉及到数据库与对象模型之间的映射问题,以及Hibernate框架在处理这些映射时可能产生的错误。下面将对这些异常进行详细的解释和分析...

    微软内部资料-SQL性能优化3

    Another type of table lock is a schema stability lock (Sch-S) and is compatible with all table locks except the schema modification lock (Sch-M). The schema modification lock (Sch-M) is incompatible ...

    NewSID(光学习一下代码就可以了,没看清楚介绍别运行)

    When the SID is found in a value it is replaced with the new computer SID, and when the SID is found in a name, the key and its subkeys are copied to a new subkey that has the same name except with ...

    微软内部资料-SQL性能优化5

    Each index row in node pages contains an index key (or set of keys for a composite index) and a pointer to a page at the next level for which the first key value is the same as the key value in the ...

    Hibernate Reference Documentation3.1

    10.9. Replicating object between two different datastores 10.10. Flushing the Session 10.11. Transitive persistence 10.12. Using metadata 11. Transactions And Concurrency 11.1. Session and transaction...

    servlet2.4doc

    Adds a response header with the given name and value. addIntHeader(String, int) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to call ...

    VclZip pro v3.10.1

    This was due to a problem where it would be freed automatically if there was a problem with the ArchiveStream when trying to open it as a zip file (possibly corrupt). Best practice is that ...

    developing android application with adobe air.part3.rar

    Chapter 1 : AIR Installing the Adobe Development Tools Installing the AIR Runtime on an Android Device What Is in the AIR SDK New ActionScript Libraries AIR on the Desktop Versus AIR on Android Mobile...

    hibernate.properties

    ## to use the second-level cache with JTA, Hibernate must be able to obtain the JTA TransactionManager #hibernate.transaction.manager_lookup_class org.hibernate.transaction....

    高性能消息传输机制Aeron.zip

    two and must be the same length on both ends.Term ID: A unique identifier for a Term within a Stream. Starts randomly. Must increase monotonically. Can wrap around. Can not go back to a wrapped ...

    hibernate 重点知识原创

    OID(Object Identifier)是对象在数据库中的唯一标识,类似于关系数据库中的主键。 ORM 解决了传统编程语言与关系数据库之间数据表示的不匹配问题,通过元数据(如 .hbm.xml 文件)定义对象与数据库表之间的映射...

    Hibernate+中文文档

    11.2.3. 异常处理 11.2.4. 事务超时 11.3. 乐观并发控制(Optimistic concurrency control) 11.3.1. 应用程序级别的版本检查(Application version checking) 11.3.2. 扩展周期的session和自动版本化 11.3.3. 脱...

Global site tag (gtag.js) - Google Analytics