mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 16:15:06 +00:00
HHH-17491 Fix checking subtype attribute declared in MappedSuperclass
This commit is contained in:
parent
9ace529732
commit
b9ff9744a3
@ -12,7 +12,9 @@
|
|||||||
import org.hibernate.metamodel.MappingMetamodel;
|
import org.hibernate.metamodel.MappingMetamodel;
|
||||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
import org.hibernate.metamodel.mapping.MappingModelHelper;
|
import org.hibernate.metamodel.mapping.MappingModelHelper;
|
||||||
|
import org.hibernate.metamodel.mapping.ModelPart;
|
||||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||||
|
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||||
@ -61,18 +63,44 @@ static boolean isCompatible(
|
|||||||
if ( attribute1 == attribute2 ) {
|
if ( attribute1 == attribute2 ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final MappingMetamodel mappingMetamodel = jpaMetamodel.getMappingMetamodel();
|
final MappingMetamodel runtimeMetamodels = jpaMetamodel.getMappingMetamodel();
|
||||||
final EntityMappingType entity1 = mappingMetamodel.getEntityDescriptor(
|
final ModelPart modelPart1 = getEntityAttributeModelPart(
|
||||||
attribute1.getDeclaringType().getTypeName()
|
attribute1,
|
||||||
|
attribute1.getDeclaringType(),
|
||||||
|
runtimeMetamodels
|
||||||
);
|
);
|
||||||
final EntityMappingType entity2 = mappingMetamodel.getEntityDescriptor(
|
final ModelPart modelPart2 = getEntityAttributeModelPart(
|
||||||
attribute2.getDeclaringType().getTypeName()
|
attribute2,
|
||||||
|
attribute2.getDeclaringType(),
|
||||||
|
runtimeMetamodels
|
||||||
);
|
);
|
||||||
|
return modelPart1 != null && modelPart2 != null && MappingModelHelper.isCompatibleModelPart(
|
||||||
|
modelPart1,
|
||||||
|
modelPart2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return entity1 != null && entity2 != null && MappingModelHelper.isCompatibleModelPart(
|
static ModelPart getEntityAttributeModelPart(
|
||||||
entity1.findSubPart( attribute1.getName() ),
|
PersistentAttribute<?, ?> attribute,
|
||||||
entity2.findSubPart( attribute2.getName() )
|
ManagedDomainType<?> domainType,
|
||||||
);
|
MappingMetamodel mappingMetamodel) {
|
||||||
|
if ( domainType instanceof EntityDomainType<?> ) {
|
||||||
|
final EntityMappingType entity = mappingMetamodel.getEntityDescriptor( domainType.getTypeName() );
|
||||||
|
return entity.findSubPart( attribute.getName() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ModelPart candidate = null;
|
||||||
|
for ( ManagedDomainType<?> subType : domainType.getSubTypes() ) {
|
||||||
|
final ModelPart modelPart = getEntityAttributeModelPart( attribute, subType, mappingMetamodel );
|
||||||
|
if ( modelPart != null ) {
|
||||||
|
if ( candidate != null && !MappingModelHelper.isCompatibleModelPart( candidate, modelPart ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
candidate = modelPart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <J, S> ManagedDomainType<S> findSubType(ManagedDomainType<J> type, Class<S> subtype) {
|
public static <J, S> ManagedDomainType<S> findSubType(ManagedDomainType<J> type, Class<S> subtype) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user