10.2. Dedicated version number
<div class="paragraph">
The version number mechanism for optimistic locking is provided through a `@Version` annotation.
</div>
<div id="locking-optimistic-version-number-example" class="exampleblock">
<div class="title">Example 276. @Version annotation</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight">`@Version
private long version;`</pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
Here, the version property is mapped to the `version` column, and the entity manager uses it to detect conflicting updates,
and prevent the loss of updates that would otherwise be overwritten by a last-commit-wins strategy.
</div>
<div class="paragraph">
The version column can be any kind of type, as long as you define and implement the appropriate `UserVersionType`.
</div>
<div class="paragraph">
Your application is forbidden from altering the version number set by Hibernate.
To artificially increase the version number, see the documentation for properties `LockModeType.OPTIMISTIC_FORCE_INCREMENT` or
`LockModeType.PESSIMISTIC_FORCE_INCREMENT` check in the Hibernate Entity Manager reference documentation.
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
</td>
<td class="content">
<div class="paragraph">
If the version number is generated by the database, such as a trigger, use the annotation `@org.hibernate.annotations.Generated(GenerationTime.ALWAYS)` on the version attribute.
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">