Optimistic Lock gives more control on concurrent modification on data. That can be achieved very easily in hibernate using @Version column. But in some cases we may have to avoid concurrency check, example background process.
To disable Optimistic lock set OptimisticLockMode as NONE for entity class while hibernate is initiating.
We can't remove version column that needs Database changes and ORM changes. In this way we can disable Optimistic Lock by code.
implement "org.hibernate.event.Initializable" interface override the below method.
To disable Optimistic lock set OptimisticLockMode as NONE for entity class while hibernate is initiating.
We can't remove version column that needs Database changes and ORM changes. In this way we can disable Optimistic Lock by code.
implement "org.hibernate.event.Initializable" interface override the below method.
@OverrideIterator propertyIterator = persistentClass.getDeclaredPropertyIterator();
public void initialize(Configuration cfg) {
Iterator<?> persistentClassIterator = cfg.getClassMappings();
while (persistentClassIterator.hasNext()) {
PersistentClass persistentClass = PersistentClass.class.cast(persistentClassIterator.next());
while (propertyIterator.hasNext()) {
Property property = Property.class.cast(propertyIterator.next());
property.setOptimisticLocked(false);}
}
}
Comments
Post a Comment