HHH-14467 Fix relative ordering of second pass for associations and derived IDs

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 <yoann@hibernate.org>
This commit is contained in:
Yoann Rodière 2021-02-23 18:27:37 +01:00
parent 496e5995b2
commit 9b991310b5
1 changed files with 25 additions and 12 deletions

View File

@ -66,19 +66,32 @@ public class ToOneFkSecondPass extends FkSecondPass {
//try explicit identifier property //try explicit identifier property
return path.startsWith( property.getName() + "." ); return path.startsWith( property.getName() + "." );
} }
else { //try the embedded property
//try the embedded property //embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor
//embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor else if ( path.startsWith( "id." ) ) {
if ( path.startsWith( "id." ) ) { KeyValue valueIdentifier = persistentClass.getIdentifier();
KeyValue valueIdentifier = persistentClass.getIdentifier(); String localPath = path.substring( 3 );
String localPath = path.substring( 3 ); if ( valueIdentifier instanceof Component ) {
if ( valueIdentifier instanceof Component ) { Iterator it = ( (Component) valueIdentifier ).getPropertyIterator();
Iterator it = ( (Component) valueIdentifier ).getPropertyIterator(); while ( it.hasNext() ) {
while ( it.hasNext() ) { Property idProperty = (Property) it.next();
Property idProperty = (Property) it.next(); if ( localPath.startsWith( idProperty.getName() ) ) {
if ( localPath.startsWith( idProperty.getName() ) ) return true; 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;
} }
} }
} }
} }