Skip to content

Commit

Permalink
HHH-11038 : Invalid statement generated for @MapKeyColumn(updatable=f…
Browse files Browse the repository at this point in the history
…alse) for @OneToMany

(cherry picked from commit 87e69c9)
  • Loading branch information
gbadner committed Sep 19, 2016
1 parent c13224f commit b936f21
Showing 1 changed file with 21 additions and 5 deletions.
Expand Up @@ -84,7 +84,11 @@ protected String generateDeleteString() {
.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 ) {
Expand All @@ -108,7 +112,11 @@ protected String generateInsertRowString() {
.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
Expand All @@ -132,7 +140,11 @@ protected String generateUpdateRowString() {
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();
Expand All @@ -149,7 +161,11 @@ protected String generateDeleteRowString() {
.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() ) {
Expand Down Expand Up @@ -191,7 +207,7 @@ private void writeIndex(
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 );
Expand Down

0 comments on commit b936f21

Please sign in to comment.