HHH-14467 Simplify detection of *ToOne associations that are part of the entity identifier

This commit is contained in:
Gail Badner 2021-02-24 20:11:48 -08:00 committed by Yoann Rodière
parent b6b83536e6
commit 021b2741ab
1 changed files with 8 additions and 18 deletions

View File

@ -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;
}