HHH-11376 - Malformed SQL query sent to SQL Server with left outer join and pessimistic lock
This commit is contained in:
parent
5f0ae6fcb7
commit
a506f53a5c
|
@ -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;
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue