I'm using Hibernate Annotations 3.1beta8 and I'm trying to implement optimistic locking on an existing table. To enforce version numbering the version number field is automatically updated by a database trigger, and that trigger throws an error if the application tries to update the version number.
If I mark the field as versioned
Code:
'@Version private int record_version_number;'
then hibernate tries to set the field on every update causing the update to fail. If I set the field as not updatable
Code:
@Version @Column(updatable=false) private int record_version_number;
then hibernate doesn't do optimistic locking. Adding '@GeneratedValue' to it doesn't change anything.
Is there anyway to tell hibernate to do optimistic locking but not try to update the version number itself? Also more generally is there anyway to tell Hibernate the column is updated by the database on every update, not just on insert?