I would like to be able to enable optimistic locking using a version column that contains a timestamp. Since we're using a legacy database that cannot be changed simply, we prefer using the existing timestamp column instead of introducing a new version index column. The application can be deployed on multiple instances on which the system time is not necessarily synchronized, so we need to fetch the current timestamp from the database. I'm using hibernate with annotations. My domain classes now simply contain:
Code:
@Version
@Column(name = "last_modified")
private Date lastModificationDate;
This obviously works, but it uses the local system timestamp instead of fetching the database time. In a mapping file you can use source="db" as follows:
Code:
<timestamp name="lastModificationDate" column="last_modified" source="db"/>
How can I configure the same thing using annotations?