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

Activity

Show:
Gail Badner
June 22, 2016, 8:16 PM

Please attach a runnable test case that reproduces your issue. The test code at https://github.com/hibernate/hibernate-test-case-templates can be used to create a runnable test case.

Mirek Sz
June 23, 2016, 6:15 AM
Gail Badner
June 23, 2016, 10:00 PM

thanks for the test case!

Mirek Sz
May 14, 2020, 3:52 PM

Even in org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(LockMode, LoadQueryInfluencers) there is comment about it

Assignee

Unassigned

Reporter

Mirek Sz

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Critical
Configure