`

关联加载对象时的报错-----a different object with the same identifier value

阅读更多

因为在hibernate中同一个session里面有了两个相同标识

但是是不同实体,当这时运行saveOrUpdate(object)操作的时候就会报这个错误。

 

所以产生这个错误的直接原因有很多。

 

我做的这个项目的产生错误是因为:

 

数据关联加载。

 

详细的意思如下:

 

Course --关联-- Major

(并自身关联自身--先修课程)

 

有Course A 关联 Major B ,同时 A 还关联 Course C(C是A的先修课程,并假设C 也关联 专业B)

 

 

在保存A时,同时会级联保存B,并且要保存和A相关的先修C。

 

如果此时你的Session里加载了C,并且C是关联加载的。也就是说Session里还有C的B。

 

所以Session中存在两个B,此时SaveOrUpdate时,就会报这样的错误。

 

所以你要关联加载对象时,要注意这个错误!

分享到:
评论

相关推荐

    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常见异常

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

    计算机网络第六版答案

    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 ...

    微软内部资料-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 ...

    微软内部资料-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 ...

    hibernate常见错误解决方案

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

    hibernate常见问题及处理.doc

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

    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 ...

Global site tag (gtag.js) - Google Analytics