HHH-11376 - Malformed SQL query sent to SQL Server with left outer join and pessimistic lock

This commit is contained in:
Andrea Boriero 2017-01-10 18:20:03 +00:00
parent 5f0ae6fcb7
commit a506f53a5c
2 changed files with 7 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
@ -113,7 +114,7 @@ public class LockOptions implements Serializable {
*/
public LockOptions setAliasSpecificLockMode(String alias, LockMode lockMode) {
if ( aliasSpecificLockModes == null ) {
aliasSpecificLockModes = new HashMap<String,LockMode>();
aliasSpecificLockModes = new LinkedHashMap<>();
}
aliasSpecificLockModes.put( alias, lockMode );
return this;

View File

@ -146,7 +146,7 @@ abstract class AbstractTransactSQLDialect extends Dialect {
// TODO: merge additional lockoptions support in Dialect.applyLocksToSql
final Iterator itr = aliasedLockOptions.getAliasLockIterator();
final StringBuilder buffer = new StringBuilder( sql );
int correction = 0;
while ( itr.hasNext() ) {
final Map.Entry entry = (Map.Entry) itr.next();
final LockMode lockMode = (LockMode) entry.getValue();
@ -155,16 +155,16 @@ abstract class AbstractTransactSQLDialect extends Dialect {
int start = -1;
int end = -1;
if ( sql.endsWith( " " + alias ) ) {
start = ( sql.length() - alias.length() ) + correction;
start = ( buffer.length() - alias.length() );
end = start + alias.length();
}
else {
int position = sql.indexOf( " " + alias + " " );
int position = buffer.indexOf( " " + alias + " " );
if ( position <= -1 ) {
position = sql.indexOf( " " + alias + "," );
position = buffer.indexOf( " " + alias + "," );
}
if ( position > -1 ) {
start = position + correction + 1;
start = position + 1;
end = start + alias.length();
}
}
@ -172,7 +172,6 @@ abstract class AbstractTransactSQLDialect extends Dialect {
if ( start > -1 ) {
final String lockHint = appendLockHint( aliasedLockOptions, alias );
buffer.replace( start, end, lockHint );
correction += ( lockHint.length() - alias.length() );
}
}
}