Skip to content

Commit

Permalink
HHH-14467 Fix relative ordering of second pass for associations and d…
Browse files Browse the repository at this point in the history
…erived 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>
  • Loading branch information
yrodiere committed Mar 1, 2021
1 parent 00cc7d9 commit 27ceeed
Showing 1 changed file with 25 additions and 12 deletions.
Expand Up @@ -66,19 +66,32 @@ else if ( property != null) {
//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;
}

}
}
}
Expand Down

0 comments on commit 27ceeed

Please sign in to comment.