Comparison operator options for Optimistic Locking in Hibernate ORM

Hello !,

When optimistically locking using the annotation @Version for concurrency control in hibernate ORM,

Is there a way to perform size comparison operations instead of equality operations for types int, Integer, short, Short, long, Long and java.sql.Timestamp?

For example, assuming that the column name for comparing @Version is version,

I want a query like this:

update {table} set column_a = :column_a_data where version <= :current_version


update {table} set column_a = :column_a_data where version < :current_version

If there is no way, could I contribute to add this option to hibnernate orm?

Thanks in advance.

Optimistic locking works by checking if a version value is still the same as it was when the data was first read. It IMO makes no sense to use any comparison operator other than =. You should never set the version to a value manually and let Hibernate ORM deal with the value.

1 Like