Optimsitic locking has to be set explicitly?

When I read a versioned entity in a transaction with a query that also sets the lock mode to optimistic explicitly, then hibernate tests the version when the read transaction commits to see if the version has changed.

This is what I expect of repeatable-read.

But if I don’t set a lock mode explicitly then hibernate doesn’t test the version on commit. Isn’t optimistic locking supposed to be default for a versioned entity?

(Hibernate 6.6)

No, if you don’t request locking explicitly Hibernate will use LockMode.NONE by default, regardless if the queried entity has a version attribute or not. You can read more about locking in this chapter of our user guide.