Version (optional) by R4R Team

Hibernate has the some different kind of tag in which we found the <version> element is optional and indicates that the table contains versioned data. <version> is particularly useful if you plan to use long transactions. See below for more information:

<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.


the name of a property of the persistent class.


defaults to integer.

the type of the version number.


defaults to property.

the strategy Hibernate uses to access the property value.


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 generated by the database. See the discussion of generated properties for more information.


defaults to true.

specifies whether the version column should be included in SQL insert statements. It can be set to false if the database column is defined with a default value of 0.

Version numbers can be of Hibernate type long, integer, short, timestamp or calendar.

A version or timestamp property should never be null for a detached instance. Hibernate will detect any instance with a null version or timestamp as transient, irrespective of what other unsaved-value strategies are specified. Declaring a nullable version or timestamp property is an easy way to avoid problems with transitive reattachment in Hibernate. It is especially useful for people using assigned identifiers or composite keys.

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!