Skip to content

Commit 9b99131

Browse files
committed
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 <[email protected]>
1 parent 496e599 commit 9b99131

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,32 @@ else if ( property != null) {
6666
//try explicit identifier property
6767
return path.startsWith( property.getName() + "." );
6868
}
69-
else {
70-
//try the embedded property
71-
//embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor
72-
if ( path.startsWith( "id." ) ) {
73-
KeyValue valueIdentifier = persistentClass.getIdentifier();
74-
String localPath = path.substring( 3 );
75-
if ( valueIdentifier instanceof Component ) {
76-
Iterator it = ( (Component) valueIdentifier ).getPropertyIterator();
77-
while ( it.hasNext() ) {
78-
Property idProperty = (Property) it.next();
79-
if ( localPath.startsWith( idProperty.getName() ) ) return true;
69+
//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 );
74+
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+
}
81+
}
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 ) {
89+
Iterator it = ( (Component) valueIdentifier ).getPropertyIterator();
90+
while ( it.hasNext() ) {
91+
Property idProperty = (Property) it.next();
92+
if ( path.equals( idProperty.getName() ) ) {
93+
return true;
8094
}
81-
8295
}
8396
}
8497
}

0 commit comments

Comments
 (0)