PESSIMISTIC_WRITE doesn't autoFlush before find/lock

Description

Code [0] fails with [1]. I am just trying to pesimistically lock an entity in the same transaction where I created it.

The cause is:
1) Entity has SEQUENCE id generator, Hibernate doesn't flush before the find() nor before the lock().
2) With PESSIMISTIC_WRITE Hibernate has to issue SELECT FOR UPDATE.

Because entity is not inserted at the time of the SELECT FOR UPDATE, the find/lock fails....

Currently I workaround this by flushing before acquiring the pessimistic lock.

[0]

[1]

Environment

None

Assignee

Unassigned

Reporter

Filip Nguyen

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Critical
Configure