浏览 3758 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2003-10-22
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2003-10-22
引用 unsaved-value (optional - defaults to null): An identifier property value that indicates that an instance is newly instantiated (unsaved), distinguishing it from transient instances that were saved or loaded in a previous session. The unsaved-value attribute is important! If the identfier property of your class does not default to null, then you should specify the actual default. 引用 assigned lets the application to assign an identifier to the object before save() is called. 引用 The unsaved-value attribute is used to specify the identifier value of a newly instantiated instance. unsaved-value defaults to "null", which is perfect for a Long identifier type. If we would have used a primitive identitifier property, we would need to specify 引用 The following code will update parent and child and insert newChild. //parent and child were both loaded in a previous session parent.addChild(child); Child newChild = new Child(); parent.addChild(newChild); session.update(parent); session.flush(); Well, thats all very well for the case of a generated identifier, but what about assigned identifiers and composite identifiers? This is more difficult, since unsaved-value can't distinguish between a newly instantiated object (with an identifier assigned by the user) and an object loaded in a previous session. In these cases, you will probably need to give Hibernate a hint; either 1. set unsaved-value="none" and explicitly save() newly instantiated children 2. set unsaved-value="any" and explicitly update() loaded children before calling update(parent). The first option is probably more sensible and so that is the default unsaved-value for assigned and composite identifiers. There is one further possibility. There is a new Interceptor method named isUnsaved() which lets the application implement its own strategy for distinguishing newly instantiated objects. |
|
返回顶楼 | |
发表时间:2003-10-22
to yehs220,多谢整理,有了此贴豁然开朗。
|
|
返回顶楼 | |
发表时间:2003-11-11
补充一下:
unsaved-value: This is the value used to determine if a class has been made persistent, i.e., stored to the database. If the value of the id attribute is null, Hibernate knows that this object has not been persisted. This is important when calling the saveOrUpdate() method, discussed later. |
|
返回顶楼 | |
发表时间:2003-11-11
引用 The generator element describes the method used to generate primary keys. I’ve chosen to use the hilo generator for purposes of illustration. The hilo generator will use a supporting
table to create the key values. If this method doesn’t appeal to you, don’t worry. In Hibernate2.0, ten primary key generation methods are available and it’s possible to create your own mechanism, including composite primary keys. |
|
返回顶楼 | |