Skip to content

Commit

Permalink
HHH-18026 Fix SQL Exception for dialects not supporting arbitrary keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed May 20, 2024
1 parent c23d75c commit 19c42b3
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public BasicResult<?> buildResult(
"t"
);

final int position = valuesArrayPosition == null ?
columnIndex( jdbcResultsMetadata, modelPart ) :
valuesArrayPosition;
final int position = valuesArrayPosition != null ?
valuesArrayPosition :
columnIndex( jdbcResultsMetadata, modelPart );
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
ResultsHelper.resolveSqlExpression(
creationStateImpl,
Expand All @@ -103,19 +103,16 @@ public BasicValuedModelPart getModelPart() {
}

private static int columnIndex(JdbcValuesMetadata jdbcResultsMetadata, BasicValuedModelPart modelPart) {
try {
if ( jdbcResultsMetadata.getColumnCount() == 1 ) {
assert modelPart.isEntityIdentifierMapping() || jdbcResultsMetadata.resolveColumnPosition(
getActualGeneratedModelPart( modelPart ).getSelectionExpression()
) == 1;
return 0;
}
else {
return jdbcPositionToValuesArrayPosition( jdbcResultsMetadata.resolveColumnPosition(
getActualGeneratedModelPart( modelPart ).getSelectionExpression()
) );
}
catch (Exception e) {
if ( modelPart.isEntityIdentifierMapping() ) {
// Default to the first position for entity identifiers
return 0;
}
else {
throw e;
}
}
}
}

0 comments on commit 19c42b3

Please sign in to comment.