The <version> element is optional and indicates that the table contains versioned data. This is particularly useful if you plan to use long transactions (see below).
<version
column="version_column"
name="propertyName"
type="typename"
access="field|property|ClassName"
unsaved-value="null|negative|undefined"
generated="never|always"
insert="true|false"
node="element-name|@attribute-name|element/@attribute|."
/>
column (optional - defaults to the property name): The name of the column holding the version number.
name: The name of a property of the persistent class.
type (optional - defaults to integer): The type of the version number.
access (optional - defaults to property): The strategy Hibernate should use for accessing the property value.
unsaved-value (optional - defaults to undefined): A version property value that indicates that an instance is newly instantiated (unsaved), distinguishing it from detached instances that were saved or loaded in a previous session. (undefined specifies that the identifier property value should be used.)
generated (optional - defaults to never): Specifies that this version property value is actually generated by the database. See the discussion of Section 5.6, “Generated Properties” generated properties.
insert (optional - defaults to true): Specifies whether the version column should be included in SQL insert statements. May be set to false if and only if the database column is defined with a default value of 0.
Version numbers may be of Hibernate type long, integer, short, timestamp or calendar.
A version or timestamp property should never be null for a detached instance, so Hibernate will detact any instance with a null version or timestamp as transient, no matter what other unsaved-value strategies are specified. Declaring a nullable version or timestamp property is an easy way to avoid any problems with transitive reattachment in Hibernate, especially useful for people using assigned identifiers or composite keys!