Fix wrong key model of FK for inverse FK side
This commit is contained in:
parent
867dd52ab3
commit
a864e25339
|
@ -61,6 +61,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
|||
private AssociationKey associationKey;
|
||||
|
||||
public EmbeddedForeignKeyDescriptor(
|
||||
EmbeddableValuedModelPart keyMappingType,
|
||||
EmbeddableValuedModelPart targetMappingType,
|
||||
String keyTable,
|
||||
SelectableMappings keySelectableMappings,
|
||||
|
@ -72,11 +73,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
|||
this.targetTable = targetTable;
|
||||
this.targetSelectableMappings = targetSelectableMappings;
|
||||
this.targetMappingType = targetMappingType;
|
||||
this.keyMappingType = EmbeddedAttributeMapping.createInverseModelPart(
|
||||
targetMappingType,
|
||||
keySelectableMappings,
|
||||
creationProcess
|
||||
);
|
||||
this.keyMappingType = keyMappingType;
|
||||
|
||||
creationProcess.registerInitializationCallback(
|
||||
"Embedded (composite) FK descriptor " + targetMappingType.getNavigableRole(),
|
||||
|
|
|
@ -1134,6 +1134,11 @@ public class MappingModelCreationHelper {
|
|||
if ( inverse ) {
|
||||
return new EmbeddedForeignKeyDescriptor(
|
||||
embeddableValuedModelPart,
|
||||
EmbeddedAttributeMapping.createInverseModelPart(
|
||||
embeddableValuedModelPart,
|
||||
keySelectableMappings,
|
||||
creationProcess
|
||||
),
|
||||
embeddableValuedModelPart.getContainingTableExpression(),
|
||||
embeddableValuedModelPart.getEmbeddableTypeDescriptor(),
|
||||
keyTableExpression,
|
||||
|
@ -1143,6 +1148,11 @@ public class MappingModelCreationHelper {
|
|||
}
|
||||
else {
|
||||
return new EmbeddedForeignKeyDescriptor(
|
||||
EmbeddedAttributeMapping.createInverseModelPart(
|
||||
embeddableValuedModelPart,
|
||||
keySelectableMappings,
|
||||
creationProcess
|
||||
),
|
||||
embeddableValuedModelPart,
|
||||
keyTableExpression,
|
||||
keySelectableMappings,
|
||||
|
|
|
@ -610,9 +610,6 @@ public class ToOneAttributeMapping
|
|||
);
|
||||
}
|
||||
|
||||
//noinspection rawtypes
|
||||
final DomainResult keyResult;
|
||||
|
||||
/*
|
||||
1. No JoinTable
|
||||
Model:
|
||||
|
@ -637,15 +634,21 @@ public class ToOneAttributeMapping
|
|||
|
||||
*/
|
||||
|
||||
final boolean isKeyReferringSide;
|
||||
if ( isFetchingForeignKey( fetchParent.getNavigablePath() ) ) {
|
||||
isKeyReferringSide = !this.isKeyReferringSide;
|
||||
}
|
||||
else{
|
||||
isKeyReferringSide = this.isKeyReferringSide;
|
||||
}
|
||||
final DomainResult<?> keyResult = foreignKeyDescriptor.createDomainResult( fetchablePath, parentTableGroup, isKeyReferringSide, creationState );
|
||||
boolean selectByUniqueKey;
|
||||
if ( isKeyReferringSide ) {
|
||||
// case 1.2
|
||||
keyResult = foreignKeyDescriptor.createDomainResult( fetchablePath, parentTableGroup, creationState );
|
||||
selectByUniqueKey = false;
|
||||
}
|
||||
else {
|
||||
// case 1.1
|
||||
keyResult = foreignKeyDescriptor.createDomainResult( fetchablePath, parentTableGroup, isKeyReferringSide, creationState );
|
||||
selectByUniqueKey = bidirectionalAttributeName != null;
|
||||
}
|
||||
|
||||
|
@ -669,6 +672,16 @@ public class ToOneAttributeMapping
|
|||
);
|
||||
}
|
||||
|
||||
private boolean isFetchingForeignKey(NavigablePath p) {
|
||||
while ( p != null ) {
|
||||
if ( ForeignKeyDescriptor.PART_NAME.equals( p.getLocalName() ) ) {
|
||||
return true;
|
||||
}
|
||||
p = p.getParent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DomainResult<T> createDelayedDomainResult(
|
||||
NavigablePath navigablePath,
|
||||
|
|
Loading…
Reference in New Issue