Working with the versioning of objects
Once a record is inserted in the database, we can update it any number of times. The versioning feature of hibernate is useful when we want to know how many times a particular record has been modified. This feature is useful in sensitive applications in the finance domain, where we need to record each and every data movement.
When we use the versioning feature, hibernate inserts the initial version number as zero. Whenever a record is modified, the value of the version is increased by one.
Getting ready
To work with the versioning concept, we have to make a small change in the POJO. We have to create a field with the numeric type and declare this field with the @version
annotation so that hibernate will consider it to be the versioning column.
Creating the classes
The following code shows the Java file changes for versioning:
Source file: Employee.java
@Entity @Table(name = "employee") public class Employee { @Id @GeneratedValue @Column(name = "id...