hibernate.default_batch_fetch_size can create deadlocks

Description

In hibernate docs we can read that hibernate.default_batch_fetch_size should be 4,8,16
but I discovered strange behavior
when I load entity by session.load(Person.class, id) and hibernate has another ids in cache then generates query: select from where id IN(?,?,?) which is correct
by when I call session.load(Person.class, id, LockMode.PESSIMISTIC) then generates also query:
select from where id IN(?,?,?) for update which is incorrect and lead sometimes to deadlock in production

Environment

WIndows/Linux, PostgreSQL

Status

Assignee

Unassigned

Reporter

Mirek

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.2.19
5.0.9
5.2.0

Priority

Critical