lock optimistic_force_increment is not working when an entityManager.clear() is called

Description

In version of Hibernate 5.3.7, it was possible to have the following case inside a single transaction:

  1. Employee e = entityManager.find(Employee.class, THE_KEY_HERE);

  2. entityManager.lock(e, LockModeType.OPTIMISTIC_FORCE_INCREMENT);

  3. ... many more action on different entities

  4. entityManager.flush();

  5. entityManager.clear();

And at the end, when the transaction is committed, the Employee was saved, and his version automatically bumped.

Since we upgraded to 5.3.11, the employee version is not bumped. If we remove the entityManager.clear() the lock is working.
But in my opinion clearing the persistence context for any reason shouldn't impact the lock mechanism.

From what I found this is related to this issue https://hibernate.atlassian.net/browse/HHH-13492.

Environment

None

Status

Assignee

Gail Badner

Reporter

Cyril Boulme

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.3.7

Components

Affects versions

Priority

Major
Configure