Skip to content

Commit a58a866

Browse files
committed
HHH-10149 - Fix PostgreSQL Dialect getForUpdateString(String aliases, LockOptions lockOptions) returning a wrong value for update String when aliases is an empty String
1 parent 4428e1a commit a58a866

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.hibernate.dialect;
88

99
import org.hibernate.JDBCException;
10+
import org.hibernate.LockMode;
1011
import org.hibernate.LockOptions;
1112
import org.hibernate.PessimisticLockException;
1213
import org.hibernate.cfg.Environment;
@@ -41,6 +42,8 @@
4142
import java.sql.ResultSet;
4243
import java.sql.SQLException;
4344
import java.sql.Types;
45+
import java.util.Iterator;
46+
import java.util.Map;
4447

4548
/**
4649
* An SQL dialect for Postgres
@@ -277,7 +280,19 @@ public String getForUpdateString(String aliases, LockOptions lockOptions) {
277280
/*
278281
* Parent's implementation for (aliases, lockOptions) ignores aliases.
279282
*/
280-
return getForUpdateString(aliases);
283+
if ( "".equals( aliases ) ) {
284+
LockMode lockMode = lockOptions.getLockMode();
285+
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator();
286+
while ( itr.hasNext() ) {
287+
// seek the highest lock mode
288+
final Map.Entry<String, LockMode> entry = itr.next();
289+
final LockMode lm = entry.getValue();
290+
if ( lm.greaterThan( lockMode ) ) {
291+
aliases = entry.getKey();
292+
}
293+
}
294+
}
295+
return getForUpdateString( aliases );
281296
}
282297

283298
@Override

0 commit comments

Comments
 (0)