HHH-18026 Fix SQL Exception for dialects not supporting arbitrary keys

This commit is contained in:
Marco Belladelli 2024-04-24 15:27:51 +02:00
parent 0515b71a81
commit 421e9cf643
1 changed files with 10 additions and 13 deletions

View File

@ -76,9 +76,9 @@ public class GeneratedValueBasicResultBuilder implements ResultBuilder {
"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,
@ -103,19 +103,16 @@ public class GeneratedValueBasicResultBuilder implements ResultBuilder {
}
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;
}
}
}
}