Skip to content

Commit d6ab2fd

Browse files
committed
HHH-18511 ArrayIndexOutOfBoundsException in ImmutableFetchList
1 parent 21a69c6 commit d6ab2fd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CompoundNaturalIdMapping.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public class CompoundNaturalIdMapping extends AbstractNaturalIdMapping implement
6161
private final List<SingularAttributeMapping> attributes;
6262

6363
private List<JdbcMapping> jdbcMappings;
64+
/*
65+
This value is used to determine the size of the array used to create the ImmutableFetchList (see org.hibernate.sql.results.graph.internal.ImmutableFetchList#Builder)
66+
The Fetch is inserted into the array at a position corresponding to its Fetchable key value.
67+
*/
68+
private final int maxFetchableKeyIndex;
6469

6570
public CompoundNaturalIdMapping(
6671
EntityMappingType declaringType,
@@ -69,6 +74,14 @@ public CompoundNaturalIdMapping(
6974
super( declaringType, isMutable( attributes ) );
7075
this.attributes = attributes;
7176

77+
int maxIndex = 0;
78+
for ( SingularAttributeMapping attribute : attributes ) {
79+
if ( attribute.getFetchableKey() > maxIndex ) {
80+
maxIndex = attribute.getFetchableKey();
81+
}
82+
}
83+
this.maxFetchableKeyIndex = maxIndex + 1;
84+
7285
creationProcess.registerInitializationCallback(
7386
"Determine compound natural-id JDBC mappings ( " + declaringType.getEntityName() + ")",
7487
() -> {
@@ -531,6 +544,10 @@ public void visitSubParts(Consumer<ModelPart> consumer, EntityMappingType treatT
531544
attributes.forEach( consumer );
532545
}
533546

547+
@Override
548+
public int getNumberOfFetchableKeys() {
549+
return maxFetchableKeyIndex;
550+
}
534551

535552
public static class DomainResultImpl implements DomainResult<Object[]>, FetchParent {
536553
private final NavigablePath navigablePath;

0 commit comments

Comments
 (0)