From 021b2741ab6ec43c03c71990bf52140c3240c0dc Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 24 Feb 2021 20:11:48 -0800 Subject: [PATCH] HHH-14467 Simplify detection of *ToOne associations that are part of the entity identifier --- .../org/hibernate/cfg/ToOneFkSecondPass.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 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 f4df4aa8e8..e849bd6200 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java @@ -67,11 +67,15 @@ public class ToOneFkSecondPass extends FkSecondPass { return path.startsWith( property.getName() + "." ); } //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 ); + else { + final KeyValue valueIdentifier = persistentClass.getIdentifier(); if ( valueIdentifier instanceof Component ) { + // Embedded property starts their path with 'id.' + // See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor + String localPath = path; + if ( path.startsWith( "id." ) ) { + localPath = path.substring( 3 ); + } Iterator it = ( (Component) valueIdentifier ).getPropertyIterator(); while ( it.hasNext() ) { Property idProperty = (Property) it.next(); @@ -81,20 +85,6 @@ public class ToOneFkSecondPass extends FkSecondPass { } } } - // 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; - } - } - } - } return false; }