HHH-10149 - Fix PostgreSQL Dialect getForUpdateString(String aliases, LockOptions lockOptions) returning a wrong value for update String when aliases is an empty String

This commit is contained in:
Andrea Boriero 2015-09-25 17:16:08 +01:00
parent fc6312a73b
commit 8bdb2d7788
1 changed files with 16 additions and 1 deletions

View File

@ -7,6 +7,7 @@
package org.hibernate.dialect;
import org.hibernate.JDBCException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.PessimisticLockException;
import org.hibernate.cfg.Environment;
@ -42,6 +43,8 @@ import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Iterator;
import java.util.Map;
/**
* An SQL dialect for Postgres
@ -273,6 +276,18 @@ public class PostgreSQL81Dialect extends Dialect {
/*
* Parent's implementation for (aliases, lockOptions) ignores aliases.
*/
if ( "".equals( aliases ) ) {
LockMode lockMode = lockOptions.getLockMode();
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator();
while ( itr.hasNext() ) {
// seek the highest lock mode
final Map.Entry<String, LockMode> entry = itr.next();
final LockMode lm = entry.getValue();
if ( lm.greaterThan( lockMode ) ) {
aliases = entry.getKey();
}
}
}
return getForUpdateString( aliases );
}