I would like to use entity versioning in my application. I know a little how it works, but not quite. I know that an @Version
annotation column should be created in the entity and the object will have the version 1
value when it is stored in the database. Each substitution of any field in this entity will result in the entity being incremented by 1.
The entity has the first version at first. I obtained this entity and replaced one field, but at the same time another user also obtained this entity, also replaced the field and quickly saved the object to the database incrementing the version to 2. So while I want to save this obsolete object, how should I compare whether the entity version agrees with my object
Or different situation as in this project. The entity has a column with the version https://github.com/Netflix/genie/blob/master/genie-core/src/main/java/com/netflix/genie/core/jpa/entities/AuditEntity.java. The user can update the entity by sending a DTO object that has a version field
private void updateEntityWithDtoContents(
final ApplicationEntity entity,
final Application dto
) throws GenieException {
entity.setVersion(dto.getVersion());
}
The version in the object is set https://github.com/Netflix/genie/blob/master/genie-core/src/main/java/com/netflix/genie/core/jpa/entities/BaseEntity.java. However, here the version is just a field where the version is manually set and only writes itself to the database. So how to check if the Application is the current version with the base.
How can I check if the Application
object is the same version to ApplicationEntity
from the database?