From 38da18b3bd795c5332ad568ef44133252aa2e6d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Cedomir=20Igaly?= Date: Sun, 17 Nov 2024 12:46:00 +0100 Subject: [PATCH] HHH-18384 Preserving order of @Id annotated elements while adding to list before other elements --- .../hibernate/boot/model/internal/PropertyBinder.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java index 694079b14c..d8a096f13b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java @@ -593,7 +593,7 @@ public class PropertyBinder { MetadataBuildingContext context) { int idPropertyCounter = 0; for ( MemberDetails property : propertyContainer.propertyIterator() ) { - idPropertyCounter += addProperty( propertyContainer, property, elements, context ); + idPropertyCounter = addProperty( propertyContainer, property, elements, context, idPropertyCounter ); } return idPropertyCounter; } @@ -602,20 +602,19 @@ public class PropertyBinder { PropertyContainer propertyContainer, MemberDetails property, List inFlightPropertyDataList, - MetadataBuildingContext context) { + MetadataBuildingContext context, int idPropertyCounter) { // see if inFlightPropertyDataList already contains a PropertyData for this name, // and if so, skip it... for ( PropertyData propertyData : inFlightPropertyDataList ) { if ( propertyData.getPropertyName().equals( property.resolveAttributeName() ) ) { checkIdProperty( property, propertyData ); // EARLY EXIT!!! - return 0; + return idPropertyCounter; } } final ClassDetails declaringClass = propertyContainer.getDeclaringClass(); final TypeVariableScope ownerType = propertyContainer.getTypeAtStake(); - int idPropertyCounter = 0; final PropertyData propertyAnnotatedElement = new PropertyInferredData( declaringClass, ownerType, @@ -628,7 +627,7 @@ public class PropertyBinder { // before any association by Hibernate final MemberDetails element = propertyAnnotatedElement.getAttributeMember(); if ( hasIdAnnotation( element ) ) { - inFlightPropertyDataList.add( 0, propertyAnnotatedElement ); + inFlightPropertyDataList.add( idPropertyCounter, propertyAnnotatedElement ); handleIdProperty( propertyContainer, context, declaringClass, ownerType, element ); if ( hasToOneAnnotation( element ) ) { context.getMetadataCollector()