HHH-11038 : Invalid statement generated for @MapKeyColumn(updatable=false) for @OneToMany

(cherry picked from commit 87e69c9d34)
This commit is contained in:
Gail Badner 2016-09-18 21:44:54 -07:00
parent c13224fba0
commit b936f21b95
1 changed files with 21 additions and 5 deletions

View File

@ -84,7 +84,11 @@ public class OneToManyPersister extends AbstractCollectionPersister {
.addPrimaryKeyColumns( keyColumnNames );
if ( hasIndex && !indexContainsFormula ) {
update.addColumns( indexColumnNames, "null" );
for ( int i = 0 ; i < indexColumnNames.length ; i++ ) {
if ( indexColumnIsSettable[i] ) {
update.addColumn( indexColumnNames[i], "null" );
}
}
}
if ( hasWhere ) {
@ -108,7 +112,11 @@ public class OneToManyPersister extends AbstractCollectionPersister {
.addColumns( keyColumnNames );
if ( hasIndex && !indexContainsFormula ) {
update.addColumns( indexColumnNames );
for ( int i = 0 ; i < indexColumnNames.length ; i++ ) {
if ( indexColumnIsSettable[i] ) {
update.addColumn( indexColumnNames[i] );
}
}
}
//identifier collections not supported for 1-to-many
@ -132,7 +140,11 @@ public class OneToManyPersister extends AbstractCollectionPersister {
update.addPrimaryKeyColumns( new String[] {identifierColumnName} );
}
if ( hasIndex && !indexContainsFormula ) {
update.addColumns( indexColumnNames );
for ( int i = 0 ; i < indexColumnNames.length ; i++ ) {
if ( indexColumnIsSettable[i] ) {
update.addColumn( indexColumnNames[i] );
}
}
}
return update.toStatementString();
@ -149,7 +161,11 @@ public class OneToManyPersister extends AbstractCollectionPersister {
.addColumns( keyColumnNames, "null" );
if ( hasIndex && !indexContainsFormula ) {
update.addColumns( indexColumnNames, "null" );
for ( int i = 0 ; i < indexColumnNames.length ; i++ ) {
if ( indexColumnIsSettable[i] ) {
update.addColumn( indexColumnNames[i], "null" );
}
}
}
if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
@ -191,7 +207,7 @@ public class OneToManyPersister extends AbstractCollectionPersister {
boolean resetIndex,
SessionImplementor session) {
// If one-to-many and inverse, still need to create the index. See HHH-5732.
if ( isInverse && hasIndex && !indexContainsFormula ) {
if ( isInverse && hasIndex && !indexContainsFormula && ArrayHelper.countTrue( indexColumnIsSettable ) > 0 ) {
try {
if ( entries.hasNext() ) {
int nextIndex = resetIndex ? 0 : getSize( id, session );