any news in this subject ? i'm stuck with the same problem.
When I checked through the sources, it seemed that this is hard to solve, because :
The enhanced Table Generator does ( lines 192-194):
Code:
HashMap lockMap = new HashMap();
lockMap.put( "tbl", LockMode.UPGRADE );
this.query = dialect.applyLocksToSql( query, lockMap, CollectionHelper.EMPTY_MAP );
gives an empty map for the keyColumns!
The Dialect class passes this on to org.hibernate.sql.ForUpdateFragment
(lines 33-42)
Code:
if ( dialect.forUpdateOfColumns() ) {
String[] keyColumns = ( String[] ) keyColumnNames.get( tableAlias ); //use the id column alias
if ( keyColumns == null ) {
throw new IllegalArgumentException( "alias not found: " + tableAlias );
}
keyColumns = StringHelper.qualify( tableAlias, keyColumns );
for ( int i = 0; i < keyColumns.length; i++ ) {
addTableAlias( keyColumns[i] );
}
}
Now I think, only the Oracle Dialects return true on dialect.forUpdateOfColumns().
The enhanced TableGenerator always has an empty keyColumnMap ( because of CollectionHelper.EMPTY_MAP ).
Now
Code:
String[] keyColumns = ( String[] ) keyColumnNames.get( tableAlias );
can only produce keyColumns==null;
Therefor I cant see any way, u get around running into this error.
Not sure though :)
Sources:
-----------------------------------------
org.hibernate.sql.ForUpdateFragment
Code:
/**
* @author Gavin King
*/
public class ForUpdateFragment {
private final StringBuffer aliases = new StringBuffer();
private boolean isNowaitEnabled;
private final Dialect dialect;
public ForUpdateFragment(Dialect dialect) {
this.dialect = dialect;
}
public ForUpdateFragment(Dialect dialect, Map lockModes, Map keyColumnNames) throws QueryException {
this( dialect );
LockMode upgradeType = null;
Iterator iter = lockModes.entrySet().iterator();
while ( iter.hasNext() ) {
final Map.Entry me = ( Map.Entry ) iter.next();
final LockMode lockMode = ( LockMode ) me.getValue();
if ( LockMode.READ.lessThan( lockMode ) ) {
final String tableAlias = ( String ) me.getKey();
if ( dialect.forUpdateOfColumns() ) {
String[] keyColumns = ( String[] ) keyColumnNames.get( tableAlias ); //use the id column alias
if ( keyColumns == null ) {
throw new IllegalArgumentException( "alias not found: " + tableAlias );
}
keyColumns = StringHelper.qualify( tableAlias, keyColumns );
for ( int i = 0; i < keyColumns.length; i++ ) {
addTableAlias( keyColumns[i] );
}
}
else {
addTableAlias( tableAlias );
}
if ( upgradeType != null && lockMode != upgradeType ) {
throw new QueryException( "mixed LockModes" );
}
upgradeType = lockMode;
}
}
if ( upgradeType == LockMode.UPGRADE_NOWAIT ) {
setNowaitEnabled( true );
}
}
org.hibernate.id.enhanced.TableGenerator
Code:
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
tableName = PropertiesHelper.getString( TABLE_PARAM, params, DEF_TABLE );
if ( tableName.indexOf( '.' ) < 0 ) {
String schemaName = params.getProperty( SCHEMA );
String catalogName = params.getProperty( CATALOG );
tableName = Table.qualify( catalogName, schemaName, tableName );
}
segmentColumnName = PropertiesHelper.getString( SEGMENT_COLUMN_PARAM, params, DEF_SEGMENT_COLUMN );
segmentValue = params.getProperty( SEGMENT_VALUE_PARAM );
if ( StringHelper.isEmpty( segmentValue ) ) {
log.debug( "explicit segment value for id generator [" + tableName + '.' + segmentColumnName + "] suggested; using default [" + DEF_SEGMENT_VALUE + "]" );
segmentValue = DEF_SEGMENT_VALUE;
}
segmentValueLength = PropertiesHelper.getInt( SEGMENT_LENGTH_PARAM, params, DEF_SEGMENT_LENGTH );
valueColumnName = PropertiesHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
initialValue = PropertiesHelper.getInt( INITIAL_PARAM, params, DEFAULT_INITIAL_VALUE );
incrementSize = PropertiesHelper.getInt( INCREMENT_PARAM, params, DEFAULT_INCREMENT_SIZE );
identifierType = type;
String query = "select " + valueColumnName +
" from " + tableName + " tbl" +
" where tbl." + segmentColumnName + "=?";
HashMap lockMap = new HashMap();
lockMap.put( "tbl", LockMode.UPGRADE );
this.query = dialect.applyLocksToSql( query, lockMap, CollectionHelper.EMPTY_MAP );
update = "update " + tableName +
" set " + valueColumnName + "=? " +
" where " + valueColumnName + "=? and " + segmentColumnName + "=?";
insert = "insert into " + tableName + " (" + segmentColumnName + ", " + valueColumnName + ") " + " values (?,?)";
String defOptStrategy = incrementSize <= 1 ? OptimizerFactory.NONE : OptimizerFactory.POOL;
String optimizationStrategy = PropertiesHelper.getString( OPT_PARAM, params, defOptStrategy );
optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize );
}