Skip to content

Commit d3f5b98

Browse files
cigalymbellade
authored andcommitted
HHH-18384 Preserving order of @id annotated elements while adding to list before other elements
1 parent 7cc928d commit d3f5b98

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ static int addElementsOfClass(
593593
MetadataBuildingContext context) {
594594
int idPropertyCounter = 0;
595595
for ( MemberDetails property : propertyContainer.propertyIterator() ) {
596-
idPropertyCounter += addProperty( propertyContainer, property, elements, context );
596+
idPropertyCounter = addProperty( propertyContainer, property, elements, context, idPropertyCounter );
597597
}
598598
return idPropertyCounter;
599599
}
@@ -602,20 +602,19 @@ private static int addProperty(
602602
PropertyContainer propertyContainer,
603603
MemberDetails property,
604604
List<PropertyData> inFlightPropertyDataList,
605-
MetadataBuildingContext context) {
605+
MetadataBuildingContext context, int idPropertyCounter) {
606606
// see if inFlightPropertyDataList already contains a PropertyData for this name,
607607
// and if so, skip it...
608608
for ( PropertyData propertyData : inFlightPropertyDataList ) {
609609
if ( propertyData.getPropertyName().equals( property.resolveAttributeName() ) ) {
610610
checkIdProperty( property, propertyData );
611611
// EARLY EXIT!!!
612-
return 0;
612+
return idPropertyCounter;
613613
}
614614
}
615615

616616
final ClassDetails declaringClass = propertyContainer.getDeclaringClass();
617617
final TypeVariableScope ownerType = propertyContainer.getTypeAtStake();
618-
int idPropertyCounter = 0;
619618
final PropertyData propertyAnnotatedElement = new PropertyInferredData(
620619
declaringClass,
621620
ownerType,
@@ -628,7 +627,7 @@ private static int addProperty(
628627
// before any association by Hibernate
629628
final MemberDetails element = propertyAnnotatedElement.getAttributeMember();
630629
if ( hasIdAnnotation( element ) ) {
631-
inFlightPropertyDataList.add( 0, propertyAnnotatedElement );
630+
inFlightPropertyDataList.add( idPropertyCounter, propertyAnnotatedElement );
632631
handleIdProperty( propertyContainer, context, declaringClass, ownerType, element );
633632
if ( hasToOneAnnotation( element ) ) {
634633
context.getMetadataCollector()

0 commit comments

Comments
 (0)