29. Legacy Domain Model

Example 698. Declaring a version property in hbm.xml

  1. <!--
  2. ~ Hibernate, Relational Persistence for Idiomatic Java
  3. ~
  4. ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
  5. ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
  6. -->
  7. <version
  8. column="version_column"
  9. name="propertyName"
  10. type="typename"
  11. access="field|property|ClassName"
  12. unsaved-value="null|negative|undefined"
  13. generated="never|always"
  14. insert="true|false"
  15. node="element-name|@attribute-name|element/@attribute|."
  16. />

column

The name of the column holding the version number. Optional, defaults to the property name.

name

The name of a property of the persistent class.

type

The type of the version number. Optional, defaults to integer.

access

Hibernate’s strategy for accessing the property value. Optional, defaults to property.

unsaved-value

Indicates that an instance is newly instantiated and thus unsaved. This distinguishes it from detached instances that were saved or loaded in a previous session. The default value, undefined, indicates that the identifier property value should be used. Optional.

generated

Indicates that the version property value is generated by the database. Optional, defaults to never.

insert

Whether or not to include the version column in SQL insert statements. Defaults to true, but you can set it to false if the database column is defined with a default value of 0.

Example 699. The timestamp element in hbm.xml

  1. <!--
  2. ~ Hibernate, Relational Persistence for Idiomatic Java
  3. ~
  4. ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
  5. ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
  6. -->
  7. <timestamp
  8. column="timestamp_column"
  9. name="propertyName"
  10. access="field|property|ClassName"
  11. unsaved-value="null|undefined"
  12. source="vm|db"
  13. generated="never|always"
  14. node="element-name|@attribute-name|element/@attribute|."
  15. />

column

The name of the column which holds the timestamp. Optional, defaults to the property name

name

The name of a JavaBeans style property of Java type Date or Timestamp of the persistent class.

access

The strategy Hibernate uses to access the property value. Optional, defaults to property.

unsaved-value

A version property which indicates that the instance is newly instantiated and unsaved. This distinguishes it from detached instances that were saved or loaded in a previous session. The default value of undefined indicates that Hibernate uses the identifier property value.

source

Whether Hibernate retrieves the timestamp from the database or the current JVM. Database-based timestamps incur an overhead because Hibernate needs to query the database each time to determine the incremental next value. However, database-derived timestamps are safer to use in a clustered environment. Not all database dialects are known to support the retrieval of the database’s current timestamp. Others may also be unsafe for locking because of lack of precision.

generated

Whether the timestamp property value is generated by the database. Optional, defaults to never.