HHH-18384 Preserving order of @Id annotated elements while adding to list before other elements

This commit is contained in:
Čedomir Igaly 2024-11-17 12:46:00 +01:00 committed by Marco Belladelli
parent 7cc928dbf4
commit d3f5b98249
1 changed files with 4 additions and 5 deletions

View File

@ -593,7 +593,7 @@ public class PropertyBinder {
MetadataBuildingContext context) { MetadataBuildingContext context) {
int idPropertyCounter = 0; int idPropertyCounter = 0;
for ( MemberDetails property : propertyContainer.propertyIterator() ) { for ( MemberDetails property : propertyContainer.propertyIterator() ) {
idPropertyCounter += addProperty( propertyContainer, property, elements, context ); idPropertyCounter = addProperty( propertyContainer, property, elements, context, idPropertyCounter );
} }
return idPropertyCounter; return idPropertyCounter;
} }
@ -602,20 +602,19 @@ public class PropertyBinder {
PropertyContainer propertyContainer, PropertyContainer propertyContainer,
MemberDetails property, MemberDetails property,
List<PropertyData> inFlightPropertyDataList, List<PropertyData> inFlightPropertyDataList,
MetadataBuildingContext context) { MetadataBuildingContext context, int idPropertyCounter) {
// see if inFlightPropertyDataList already contains a PropertyData for this name, // see if inFlightPropertyDataList already contains a PropertyData for this name,
// and if so, skip it... // and if so, skip it...
for ( PropertyData propertyData : inFlightPropertyDataList ) { for ( PropertyData propertyData : inFlightPropertyDataList ) {
if ( propertyData.getPropertyName().equals( property.resolveAttributeName() ) ) { if ( propertyData.getPropertyName().equals( property.resolveAttributeName() ) ) {
checkIdProperty( property, propertyData ); checkIdProperty( property, propertyData );
// EARLY EXIT!!! // EARLY EXIT!!!
return 0; return idPropertyCounter;
} }
} }
final ClassDetails declaringClass = propertyContainer.getDeclaringClass(); final ClassDetails declaringClass = propertyContainer.getDeclaringClass();
final TypeVariableScope ownerType = propertyContainer.getTypeAtStake(); final TypeVariableScope ownerType = propertyContainer.getTypeAtStake();
int idPropertyCounter = 0;
final PropertyData propertyAnnotatedElement = new PropertyInferredData( final PropertyData propertyAnnotatedElement = new PropertyInferredData(
declaringClass, declaringClass,
ownerType, ownerType,
@ -628,7 +627,7 @@ public class PropertyBinder {
// before any association by Hibernate // before any association by Hibernate
final MemberDetails element = propertyAnnotatedElement.getAttributeMember(); final MemberDetails element = propertyAnnotatedElement.getAttributeMember();
if ( hasIdAnnotation( element ) ) { if ( hasIdAnnotation( element ) ) {
inFlightPropertyDataList.add( 0, propertyAnnotatedElement ); inFlightPropertyDataList.add( idPropertyCounter, propertyAnnotatedElement );
handleIdProperty( propertyContainer, context, declaringClass, ownerType, element ); handleIdProperty( propertyContainer, context, declaringClass, ownerType, element );
if ( hasToOneAnnotation( element ) ) { if ( hasToOneAnnotation( element ) ) {
context.getMetadataCollector() context.getMetadataCollector()