`
siemenew
  • 浏览: 6487 次
  • 性别: Icon_minigender_1
  • 来自: 嘉兴
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

update时出现 adifferent object with the same identifierm value was already ...

 
阅读更多
    这两天在做一个练习项目时的更新模块时遇到一个问题,因为更新前要判断其中的一个属性值是否有重名,该属性的值重名有两个情况:
一种是与另外一个对象或另一条数据库记录重名,这种情况下只要改变该属性得值使得其唯一再用update(object)就没有什么问题。
另一种情况是该属性得值没有发生变化,用该属性值从数据库加载上来的对象与需要update的对象具有相同的标识(id值相同),此时执行update(object)时就会报以下错误:a different object with the same identifier value was already associated with the session。

这个错误的意思是说在session存在有相同标识的持久化对象,因此无法更新,一开始我的注意力放在如何把另外一个对象从session中去掉,结果试了很多方法都无法圆满的解决。

后来在查看HibernateTemplate的的方法时发现merge方法
merge(Object entity) : Copy the state of the given object onto the persistent object with the same identifier.

用这个方法代替update问题得到解决。

看来merge方法仅仅是把对象拷贝到session并更新数据库,而对象还是处于脱管状态。

分享到:
评论

相关推荐

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

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

    Java邮件开发Fundamentals of the JavaMail API

    A general familiarity with object-oriented programming concepts and the Java programming language is necessary. The Java language essentials tutorial can help. copyright 1996-2000 Magelang ...

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

    Delphi7.1 Update

    TClientDataSet does not order correctly on a TLargeIntField when used in an index or in the IndexFieldNames property (Quality Central 1050 & 2626) * TAggregateField returns an incorrect value after a ...

    数位板压力测试

    This specification was developed in response to a perceived need for a standardized programming inter-face to digitizing tablets, three dimensional position sensors, and other pointing devices by a ...

    DebuggingWithGDB 6.8-2008

    4.7 Debugging an Already-running Process . . . . . . . . . . . . . . . . . . . . . . 4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.9 Debugging ...

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

    Git-2.21.0-64-bit.zip

    squelch the path to the object that is used as a grouping hint for pack-objects. * A new tag.gpgSign configuration variable turns "git tag -a" into "git tag -s". * "git multi-pack-index" ...

    STG (SNMP Traffic Grapher)

    Before the value of "Update Period" option was used. Features added: 1. Status bar indicator of last sample time. 2. Logging ability. If option "Write Data to Log File" is checked, then program ...

    acpi控制笔记本风扇转速

    pathname places the template within a different namespace scope than the current scope. (BZ 7212) Fixed a problem where the compiler could hang after syntax errors detected in an ElseIf construct. ...

    EurekaLog_7.5.0.0_Enterprise

    18)..Fixed: Possible "Unit XYZ was compiled with a different version of ABC" when using packages 19)..Fixed: FastMM shared MM compatibility 20)..Fixed: Minor bugs in stack tracing (which usually ...

    EhLib5.0.13 最新的ehlib源码

    Printer.Handle is the same but in TPrinterPreview PrinterPreview.Canvas.Handle represent the metafile in that is recored the data and PrinterPreview.Handle represent Printer.Handle. That is mean that...

    EhLib 6.3 Build 6.3.176 Russian version. Full source included.

    Printer.Handle is the same but in TPrinterPreview PrinterPreview.Canvas.Handle represent the metafile in that is recored the data and PrinterPreview.Handle represent Printer.Handle. That is mean that...

    TICQClient Version

    Affiliations, etc) in Example having the same group names caused errors: the first group and value were repeated a few times instead of showing the different values with the same groups01-July-2002, ...

Global site tag (gtag.js) - Google Analytics