From 9b991310b52612c5e1ec8c6c92e4caad55b45d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Tue, 23 Feb 2021 18:27:37 +0100 Subject: [PATCH] HHH-14467 Fix relative ordering of second pass for associations and derived IDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Always execute second pass for associations referencing an entity with derived ID after the second pass for that entity's derived ID. Signed-off-by: Yoann Rodière --- .../org/hibernate/cfg/ToOneFkSecondPass.java | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java index 906d1827b0..f4df4aa8e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java @@ -66,19 +66,32 @@ public class ToOneFkSecondPass extends FkSecondPass { //try explicit identifier property return path.startsWith( property.getName() + "." ); } - else { - //try the embedded property - //embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor - if ( path.startsWith( "id." ) ) { - KeyValue valueIdentifier = persistentClass.getIdentifier(); - String localPath = path.substring( 3 ); - if ( valueIdentifier instanceof Component ) { - Iterator it = ( (Component) valueIdentifier ).getPropertyIterator(); - while ( it.hasNext() ) { - Property idProperty = (Property) it.next(); - if ( localPath.startsWith( idProperty.getName() ) ) return true; + //try the embedded property + //embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor + else if ( path.startsWith( "id." ) ) { + KeyValue valueIdentifier = persistentClass.getIdentifier(); + String localPath = path.substring( 3 ); + if ( valueIdentifier instanceof Component ) { + Iterator it = ( (Component) valueIdentifier ).getPropertyIterator(); + while ( it.hasNext() ) { + Property idProperty = (Property) it.next(); + if ( localPath.startsWith( idProperty.getName() ) ) { + return true; + } + } + } + } + // Try the case where a @ManyToOne is also an ID property + // E.g. @ManyToOne @Id SomeEntity other; + else if ( !path.contains( "." ) ) { + KeyValue valueIdentifier = persistentClass.getIdentifier(); + if ( valueIdentifier instanceof Component ) { + Iterator it = ( (Component) valueIdentifier ).getPropertyIterator(); + while ( it.hasNext() ) { + Property idProperty = (Property) it.next(); + if ( path.equals( idProperty.getName() ) ) { + return true; } - } } }