From f24669ca9320be5f6da396d24baf5965c93c9de1 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 22 Jan 2024 14:47:41 +0100 Subject: [PATCH] HHH-17420 JoinColumn throws an AnnotationException --- .../boot/model/internal/BinderHelper.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java index 90014ae155..6a4bfdf6c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java @@ -452,9 +452,16 @@ public class BinderHelper { // which are mapped to that column. (There might be multiple such // properties for each column.) if ( columnOwner instanceof PersistentClass ) { - PersistentClass persistentClass = (PersistentClass) columnOwner; + final PersistentClass persistentClass = (PersistentClass) columnOwner; + // Process ToOne associations after Components, Basic and Id properties + final List toOneProperties = new ArrayList<>(); for ( Property property : persistentClass.getReferenceableProperties() ) { - matchColumnsByProperty( property, columnsToProperty ); + if ( property.getValue() instanceof ToOne ) { + toOneProperties.add( property ); + } + else { + matchColumnsByProperty( property, columnsToProperty ); + } } if ( persistentClass.hasIdentifierProperty() ) { matchColumnsByProperty( persistentClass.getIdentifierProperty(), columnsToProperty ); @@ -466,6 +473,9 @@ public class BinderHelper { matchColumnsByProperty( p, columnsToProperty ); } } + for ( Property property : toOneProperties ) { + matchColumnsByProperty( property, columnsToProperty ); + } } else { for ( Property property : ((Join) columnOwner).getProperties() ) {