//
// how to best (a) find the bi-directionality and (b) represent that?
if ( EntityFetch.class.isInstance( entityReference ) ) {
// we just confirmed that EntityReference(Address) is an instance of EntityFetch(Address),
final EntityFetch entityFetch = (EntityFetch) entityReference;
final FetchOwner entityFetchOwner = entityFetch.getOwner();
// so at this point we need to see if entityFetchOwner and attributeDefinition refer to the
// "same thing". "same thing" == "same type" && "same column(s)"?
//
// i make assumptions here that that the attribute type is the EntityType, is that always valid?
final EntityType attributeDefinitionTypeAsEntityType = (EntityType) attributeDefinition.getType();
final boolean sameType = attributeDefinitionTypeAsEntityType.getAssociatedEntityName().equals(
entityFetchOwner.retrieveFetchSourcePersister().getEntityName()
);
if ( sameType ) {
// check same columns as well?
return new KeyManyToOneBidirectionalEntityFetch(
sessionFactory(),
//ugh
LockMode.READ,
this,
attributeDefinition,
(EntityReference) entityFetchOwner,
fetchStrategy
);
}
}
final EntityFetch fetch = super.buildEntityFetch( attributeDefinition, fetchStrategy, loadPlanBuildingContext );
// pretty sure this HydratedCompoundValueExtractor stuff is not needed...
fetchToHydratedStateExtractorMap.put( fetch, attributeDefinition.getHydratedCompoundValueExtractor() );
return fetch;