mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-09 04:34:49 +00:00
Fix issue with SimpleForeignKeyDescriptor DomainResult creation
This commit is contained in:
parent
681c3fa9cf
commit
52b126d4cf
@ -25,7 +25,15 @@ public interface ForeignKeyDescriptor extends VirtualModelPart {
|
|||||||
|
|
||||||
ForeignKeyDirection getDirection();
|
ForeignKeyDirection getDirection();
|
||||||
|
|
||||||
DomainResult createDomainResult(NavigablePath collectionPath, TableGroup tableGroup, DomainResultCreationState creationState);
|
DomainResult createCollectionFecthDomainResult(
|
||||||
|
NavigablePath collectionPath,
|
||||||
|
TableGroup tableGroup,
|
||||||
|
DomainResultCreationState creationState);
|
||||||
|
|
||||||
|
DomainResult createDomainResult(
|
||||||
|
NavigablePath collectionPath,
|
||||||
|
TableGroup tableGroup,
|
||||||
|
DomainResultCreationState creationState);
|
||||||
|
|
||||||
Predicate generateJoinPredicate(
|
Predicate generateJoinPredicate(
|
||||||
TableGroup lhs,
|
TableGroup lhs,
|
||||||
|
@ -87,6 +87,46 @@ public ForeignKeyDirection getDirection() {
|
|||||||
return fKeyDirection;
|
return fKeyDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DomainResult createCollectionFecthDomainResult(
|
||||||
|
NavigablePath collectionPath,
|
||||||
|
TableGroup tableGroup,
|
||||||
|
DomainResultCreationState creationState) {
|
||||||
|
if ( targetColumnContainingTable.equals( keyColumnContainingTable ) ) {
|
||||||
|
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
|
||||||
|
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
|
||||||
|
final TableReference tableReference = tableGroup.resolveTableReference( keyColumnContainingTable );
|
||||||
|
final String identificationVariable = tableReference.getIdentificationVariable();
|
||||||
|
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
|
||||||
|
sqlExpressionResolver.resolveSqlExpression(
|
||||||
|
SqlExpressionResolver.createColumnReferenceKey(
|
||||||
|
tableReference,
|
||||||
|
targetColumnExpression
|
||||||
|
),
|
||||||
|
s -> {
|
||||||
|
return new ColumnReference(
|
||||||
|
identificationVariable,
|
||||||
|
targetColumnExpression,
|
||||||
|
jdbcMapping,
|
||||||
|
creationState.getSqlAstCreationState().getCreationContext().getSessionFactory()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
jdbcMapping.getJavaTypeDescriptor(),
|
||||||
|
sqlAstCreationState.getCreationContext().getDomainModel().getTypeConfiguration()
|
||||||
|
);
|
||||||
|
|
||||||
|
//noinspection unchecked
|
||||||
|
return new BasicResult(
|
||||||
|
sqlSelection.getValuesArrayPosition(),
|
||||||
|
null,
|
||||||
|
jdbcMapping.getJavaTypeDescriptor()
|
||||||
|
);
|
||||||
|
}else {
|
||||||
|
return createDomainResult( collectionPath, tableGroup, creationState );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DomainResult createDomainResult(
|
public DomainResult createDomainResult(
|
||||||
NavigablePath collectionPath,
|
NavigablePath collectionPath,
|
||||||
|
@ -177,6 +177,11 @@ else if ( keyCollectionValue != null ) {
|
|||||||
LoggingHelper.toLoggableString( getNavigablePath(), this.collectionKey.getKey() )
|
LoggingHelper.toLoggableString( getNavigablePath(), this.collectionKey.getKey() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}else {
|
||||||
|
this.collectionKey = new CollectionKey(
|
||||||
|
collectionAttributeMapping.getCollectionDescriptor(),
|
||||||
|
parentAccess.getParentKey()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,13 +61,13 @@ public EagerCollectionFetch(
|
|||||||
final ForeignKeyDescriptor keyDescriptor = fetchedAttribute.getKeyDescriptor();
|
final ForeignKeyDescriptor keyDescriptor = fetchedAttribute.getKeyDescriptor();
|
||||||
if ( parentTableGroup != null ) {
|
if ( parentTableGroup != null ) {
|
||||||
// join fetch
|
// join fetch
|
||||||
keyContainerResult = keyDescriptor.createDomainResult( fetchedPath, parentTableGroup, creationState );
|
keyContainerResult = keyDescriptor.createCollectionFecthDomainResult( fetchedPath, parentTableGroup, creationState );
|
||||||
keyCollectionResult = keyDescriptor.createDomainResult( fetchedPath, collectionTableGroup, creationState );
|
keyCollectionResult = keyDescriptor.createDomainResult( fetchedPath, collectionTableGroup, creationState );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// select fetch
|
// select fetch
|
||||||
// todo (6.0) : we could potentially leverage batch fetching for performance
|
// todo (6.0) : we could potentially leverage batch fetching for performance
|
||||||
keyContainerResult = keyDescriptor.createDomainResult( fetchedPath, collectionTableGroup, creationState );
|
keyContainerResult = keyDescriptor.createCollectionFecthDomainResult( fetchedPath, collectionTableGroup, creationState );
|
||||||
|
|
||||||
// use null for `keyCollectionResult`... the initializer will see that as trigger to use
|
// use null for `keyCollectionResult`... the initializer will see that as trigger to use
|
||||||
// the assembled container-key value as the collection-key value.
|
// the assembled container-key value as the collection-key value.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user