Skip to content

Commit 021b274

Browse files
gbadneryrodiere
authored andcommitted
HHH-14467 Simplify detection of *ToOne associations that are part of the entity identifier
1 parent b6b8353 commit 021b274

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,19 @@ else if ( property != null) {
6767
return path.startsWith( property.getName() + "." );
6868
}
6969
//try the embedded property
70-
//embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor
71-
else if ( path.startsWith( "id." ) ) {
72-
KeyValue valueIdentifier = persistentClass.getIdentifier();
73-
String localPath = path.substring( 3 );
70+
else {
71+
final KeyValue valueIdentifier = persistentClass.getIdentifier();
7472
if ( valueIdentifier instanceof Component ) {
75-
Iterator it = ( (Component) valueIdentifier ).getPropertyIterator();
76-
while ( it.hasNext() ) {
77-
Property idProperty = (Property) it.next();
78-
if ( localPath.startsWith( idProperty.getName() ) ) {
79-
return true;
80-
}
73+
// Embedded property starts their path with 'id.'
74+
// See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor
75+
String localPath = path;
76+
if ( path.startsWith( "id." ) ) {
77+
localPath = path.substring( 3 );
8178
}
82-
}
83-
}
84-
// Try the case where a @ManyToOne is also an ID property
85-
// E.g. @ManyToOne @Id SomeEntity other;
86-
else if ( !path.contains( "." ) ) {
87-
KeyValue valueIdentifier = persistentClass.getIdentifier();
88-
if ( valueIdentifier instanceof Component ) {
8979
Iterator it = ( (Component) valueIdentifier ).getPropertyIterator();
9080
while ( it.hasNext() ) {
9181
Property idProperty = (Property) it.next();
92-
if ( path.equals( idProperty.getName() ) ) {
82+
if ( localPath.startsWith( idProperty.getName() ) ) {
9383
return true;
9484
}
9585
}

0 commit comments

Comments
 (0)