Hi,
I am using managed versioning (with a numeric version), and when I create a new object, NH persists it to the database with an initial version number of zero (because Int32Type.Seed returns 0).
The issue I have come across is that when I was using either
Code:
<version name="Version" type="Int32"/>
or
Code:
<version name="Version" type="Int32" unsaved-value="0"/>
in my mapping file, this caused a crash when I updated the object and tried to re-persist it. This is because NH interpreted the version number of 0 as being unsaved and therefore tried to create another record with the same primary key.
The only way I could get my app to work is to set unsaved-value="-1" and to initialise the version number of every object to -1 before persisting it.
So my question is: why does the Hibernate In Action book give examples of mapping files with
Quote:
<version name="Version" type="Int32" unsaved-value="0"/>
when this will not allow you to update a previously persisted object?
IMHO, the problem would be neatly solved if NH made the initial version 1 instead of zero, as this would allow unsaved-value="0" to work and would remove the requirement to set the version number to -1 in the object itself.