diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractCompositionAttribute.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractCompositionAttribute.java index 953cc19f5d..f712fa4d6f 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractCompositionAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractCompositionAttribute.java @@ -92,7 +92,6 @@ public abstract class AbstractCompositionAttribute // we build the association-key here because of the "goofiness" with 'currentColumnPosition' final AssociationKey associationKey; final AssociationType aType = (AssociationType) type; - final Joinable joinable = aType.getAssociatedJoinable( sessionFactory() ); if ( aType.isAnyType() ) { associationKey = new AssociationKey( @@ -111,6 +110,8 @@ public abstract class AbstractCompositionAttribute ); } else if ( aType.getForeignKeyDirection() == ForeignKeyDirection.FROM_PARENT ) { + final Joinable joinable = aType.getAssociatedJoinable( sessionFactory() ); + final String lhsTableName; final String[] lhsColumnNames; @@ -133,6 +134,8 @@ public abstract class AbstractCompositionAttribute associationKey = new AssociationKey( lhsTableName, lhsColumnNames ); } else { + final Joinable joinable = aType.getAssociatedJoinable( sessionFactory() ); + associationKey = new AssociationKey( joinable.getTableName(), getRHSColumnNames( aType, sessionFactory() )