From a58a866e67c1d4acc5d016efc1783d6ff2a6904e Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 25 Sep 2015 17:16:08 +0100 Subject: [PATCH] HHH-10149 - Fix PostgreSQL Dialect getForUpdateString(String aliases, LockOptions lockOptions) returning a wrong value for update String when aliases is an empty String --- .../hibernate/dialect/PostgreSQL81Dialect.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java index 7b493aa2ef..f5312d65dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java @@ -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; @@ -41,6 +42,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 @@ -277,7 +280,19 @@ public class PostgreSQL81Dialect extends Dialect { /* * Parent's implementation for (aliases, lockOptions) ignores aliases. */ - return getForUpdateString(aliases); + if ( "".equals( aliases ) ) { + LockMode lockMode = lockOptions.getLockMode(); + final Iterator> itr = lockOptions.getAliasLockIterator(); + while ( itr.hasNext() ) { + // seek the highest lock mode + final Map.Entry entry = itr.next(); + final LockMode lm = entry.getValue(); + if ( lm.greaterThan( lockMode ) ) { + aliases = entry.getKey(); + } + } + } + return getForUpdateString( aliases ); } @Override