[hibernate-issues] [Hibernate-JIRA] Closed: (HHH-1044) Doc improvement for assigned identifiers and unsaved value

Steve Ebersole (JIRA) noreply at atlassian.com
Mon Mar 21 13:00:42 EDT 2011


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1044?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Steve Ebersole closed HHH-1044.
-------------------------------


Closing stale resolved issues

> Doc improvement for assigned identifiers and unsaved value
> ----------------------------------------------------------
>
>                 Key: HHH-1044
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1044
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: documentation
>    Affects Versions: 3.1 rc 1
>         Environment: hibernate 3.1 beta3, mssql
>            Reporter: John
>            Priority: Trivial
>
> --current doc--
> 6.1.4.5. Assigned identifiers
> If you want the application to assign identifiers (as opposed to having Hibernate generate them), you may use the assigned generator. This special generator will use the identifier value already assigned to the object's identifier property. This generator is used when the primary key is a natural key instead of a surrogate key. This is the default behavior if you do no specify a <generator> element.
> Choosing the assigned generator makes Hibernate use unsaved-value="undefined", forcing Hibernate to go to the database to determine if an instance is transient or detached, unless there is a version or timestamp property, or you define Interceptor.isUnsaved(). 
> --/current doc--
> I have found the part about being forced to use unsaved-value="undefined" to be true in Hibernate 2.  However, I had some mappings that were in use in Hibernate 2 that were migrated to Hibernate 3.  A little bit of copy and paste from an identity column mapping to an assigned mapping left me with a mapping like this:
>        <id name="id" column="id" type="int" unsaved-value="-1">
>             <generator class="assigned" />
>         </id>
> This worked in 2, but did not in 3.  It appeared that Hibernate worked halfway.  It did a select to determine if the row was in the database, which means it saw the assigned part.  However, even after determining the row wasn't there it still tried to do an update, indicating that at that point it was checking the unsaved-value.  The update failed since with an unexpected rowcount error.  Changing unsaved-value to "undefined" or removing the attribute completely fixed the problem and allowed the insert to work as expected.
> Obviously the mapping is internally inconsisten, but I think either Hibernate should be changed to ignore the unsaved-value for assigned ids, or the docs should be changed to better indicate that it's best to leave unsaved-value off if you are using assigned identifiers.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list