Michal Hajas (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYTcyYWQxM2Zh...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16071?atlOrigin=eyJpIjoiYTcyYW...
) HHH-16071 (
https://hibernate.atlassian.net/browse/HHH-16071?atlOrigin=eyJpIjoiYTcyYW...
) javax.persistence.lock.timeout does not fully work with PostgreSQL (
https://hibernate.atlassian.net/browse/HHH-16071?atlOrigin=eyJpIjoiYTcyYW...
)
Issue Type: Bug Affects Versions: 5.6.14 Assignee: Unassigned Components: hibernate-core
Created: 20/Jan/2023 01:56 AM Priority: Major Reporter: Michal Hajas (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
******************
Steps to reproduce
******************
* Start 1st transaction and execute SELECT .... FOR UPDATE
* Start 2nd transaction and execute SELECT ..... FOR UPDATE on the same row
* Now it hangs forever with PostgreSQL by default
It should be possible to configure javax.persistence.lock.timeout to change this
behaviour. There are more ways how to configure it.
Using EMF property
properties.put( "javax.persistence.lock.timeout" , lockTimeout);
This seems to not work at all with PostgreSQL. I tried lockTimeout ( Long ) values 0 and
1000.
Using Query hint / find properties
em.find(entityType, uuid, LockModeType.PESSIMISTIC_WRITE,
Collections.singletonMap("javax.persistence.lock.timeout", lockTimeout))
This works with lockTimeout equal to 0 but nothing else.
Is there some way to make this work with PostgreSQL? Or is this a bug?
**********
Workaround
**********
There is a workaround that makes lock timeout work with PostgreSQL but it requires a
custom configuration for each EntityManager created.
protected EntityManager getEntityManager() {
EntityManager em = emf.createEntityManager();
if ( "postgresql".equals(databaseShortName) ||
"cockroachdb".equals(databaseShortName)) {
Long lockTimeout = config.getLong( "lockTimeout" );
if (lockTimeout != null ) {
em.unwrap(SessionImpl.class)
.doWork(connection -> {
PreparedStatement preparedStatement =
connection.prepareStatement( "SET LOCAL lock_timeout = '" + lockTimeout +
"' ;" );
preparedStatement.execute();
});
}
}
return em;
}
(
https://hibernate.atlassian.net/browse/HHH-16071#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16071#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100214- sha1:fa7bc5f )