HHH-12383 - Type check existing type to avoid class cast exceptions related to type incompatible same named attributes being used in subtypes
This commit is contained in:
parent
7dd640a65e
commit
56d3ce4c2f
|
@ -127,6 +127,18 @@ public abstract class AbstractPropertyMapping implements PropertyMapping {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logIncompatibleRegistration(String path, Type existingType, Type type) {
|
||||||
|
if ( LOG.isTraceEnabled() ) {
|
||||||
|
LOG.tracev(
|
||||||
|
"Skipped adding same named type incompatible property to base type [{0}] for property [{1}], existing type = [{2}], incoming type = [{3}]",
|
||||||
|
getEntityName(),
|
||||||
|
path,
|
||||||
|
existingType,
|
||||||
|
type
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only kept around for compatibility reasons since this seems to be API.
|
* Only kept around for compatibility reasons since this seems to be API.
|
||||||
*
|
*
|
||||||
|
@ -176,11 +188,11 @@ public abstract class AbstractPropertyMapping implements PropertyMapping {
|
||||||
Type newType = null;
|
Type newType = null;
|
||||||
MetadataImplementor metadata = (MetadataImplementor) factory;
|
MetadataImplementor metadata = (MetadataImplementor) factory;
|
||||||
|
|
||||||
if ( type instanceof AnyType ) {
|
if ( type instanceof AnyType && existingType instanceof AnyType ) {
|
||||||
// TODO: not sure how to handle any types. For now we just return and let the first type dictate what type the property has...
|
// TODO: not sure how to handle any types. For now we just return and let the first type dictate what type the property has...
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ( type instanceof CollectionType ) {
|
else if ( type instanceof CollectionType && existingType instanceof CollectionType ) {
|
||||||
Collection thisCollection = metadata.getCollectionBinding( ( (CollectionType) existingType ).getRole() );
|
Collection thisCollection = metadata.getCollectionBinding( ( (CollectionType) existingType ).getRole() );
|
||||||
Collection otherCollection = metadata.getCollectionBinding( ( (CollectionType) type ).getRole() );
|
Collection otherCollection = metadata.getCollectionBinding( ( (CollectionType) type ).getRole() );
|
||||||
|
|
||||||
|
@ -195,17 +207,9 @@ public abstract class AbstractPropertyMapping implements PropertyMapping {
|
||||||
|
|
||||||
// When we discover incompatible types, we use "null" as property type to signal that the property is not resolvable on the parent type
|
// When we discover incompatible types, we use "null" as property type to signal that the property is not resolvable on the parent type
|
||||||
newType = null;
|
newType = null;
|
||||||
if ( LOG.isTraceEnabled() ) {
|
logIncompatibleRegistration(path, existingType, type);
|
||||||
LOG.tracev(
|
|
||||||
"Skipped adding same named type incompatible property to base type [{0}] for property [{1}], existing type = [{2}], incoming type = [{3}]",
|
|
||||||
getEntityName(),
|
|
||||||
path,
|
|
||||||
existingType,
|
|
||||||
type
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
else if ( type instanceof EntityType && existingType instanceof EntityType ) {
|
||||||
else if ( type instanceof EntityType ) {
|
|
||||||
EntityType entityType1 = (EntityType) existingType;
|
EntityType entityType1 = (EntityType) existingType;
|
||||||
EntityType entityType2 = (EntityType) type;
|
EntityType entityType2 = (EntityType) type;
|
||||||
|
|
||||||
|
@ -220,6 +224,9 @@ public abstract class AbstractPropertyMapping implements PropertyMapping {
|
||||||
|
|
||||||
newType = getCommonType( metadata, entityType1, entityType2 );
|
newType = getCommonType( metadata, entityType1, entityType2 );
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
logIncompatibleRegistration(path, existingType, type);
|
||||||
|
}
|
||||||
|
|
||||||
typesByPropertyPath.put( path, newType );
|
typesByPropertyPath.put( path, newType );
|
||||||
// Set everything to empty to signal action has to be taken!
|
// Set everything to empty to signal action has to be taken!
|
||||||
|
|
Loading…
Reference in New Issue