这两天在做一个练习项目时的更新模块时遇到一个问题,因为更新前要判断其中的一个属性值是否有重名,该属性的值重名有两个情况:
一种是与另外一个对象或另一条数据库记录重名,这种情况下只要改变该属性得值使得其唯一再用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并更新数据库,而对象还是处于脱管状态。
分享到:
相关推荐
- 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 ...
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 ...
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 ...
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 ...
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 ...
4.7 Debugging an Already-running Process . . . . . . . . . . . . . . . . . . . . . . 4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.9 Debugging ...
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 ...
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" ...
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 ...
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. ...
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 ...
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...
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...
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, ...