HHH-16664 NPE in MappingMetamodelImpl if inheritance is used in IdClass

This commit is contained in:
Andrea Boriero 2023-05-30 15:03:29 +02:00 committed by Andrea Boriero
parent 0147541b1c
commit e7fa3cebb6
2 changed files with 21 additions and 11 deletions

View File

@ -298,7 +298,8 @@ public class EmbeddableBinder {
compositeUserTypeClass,
columns,
context,
inheritanceStatePerClass
inheritanceStatePerClass,
false
);
}
@ -316,7 +317,8 @@ public class EmbeddableBinder {
Class<? extends CompositeUserType<?>> compositeUserTypeClass,
AnnotatedColumns columns,
MetadataBuildingContext context,
Map<XClass, InheritanceState> inheritanceStatePerClass) {
Map<XClass, InheritanceState> inheritanceStatePerClass,
boolean isIdClass) {
// inSecondPass can only be used to apply right away the second pass of a composite-element
// Because it's a value type, there is no bidirectional association, hence second pass
// ordering does not matter
@ -358,7 +360,7 @@ public class EmbeddableBinder {
final XClass annotatedClass = inferredData.getPropertyClass();
final List<PropertyData> classElements =
collectClassElements( propertyAccessor, context, returnedClassOrElement, annotatedClass );
collectClassElements( propertyAccessor, context, returnedClassOrElement, annotatedClass, isIdClass );
final List<PropertyData> baseClassElements =
collectBaseClassElements( baseInferredData, propertyAccessor, context, annotatedClass );
if ( baseClassElements != null
@ -421,7 +423,8 @@ public class EmbeddableBinder {
AccessType propertyAccessor,
MetadataBuildingContext context,
XClass returnedClassOrElement,
XClass annotatedClass) {
XClass annotatedClass,
boolean isIdClass) {
final List<PropertyData> classElements = new ArrayList<>();
//embeddable elements can have type defs
final PropertyContainer container =
@ -429,7 +432,8 @@ public class EmbeddableBinder {
addElementsOfClass( classElements, container, context);
//add elements of the embeddable's mapped superclasses
XClass superClass = annotatedClass.getSuperclass();
while ( superClass != null && superClass.isAnnotationPresent( MappedSuperclass.class ) ) {
while ( superClass != null && ( superClass.isAnnotationPresent( MappedSuperclass.class )
|| ( isIdClass && !Object.class.getName().equals( superClass.getName() ) ) ) ) {
//FIXME: proper support of type variables incl var resolved at upper levels
final PropertyContainer superContainer =
new PropertyContainer( superClass, annotatedClass, propertyAccessor );

View File

@ -405,7 +405,8 @@ public class EntityBinder {
classWithIdClass,
compositeClass,
baseInferredData,
propertyAccessor
propertyAccessor,
true
);
setIgnoreIdAnnotations( ignoreIdAnnotations );
for ( Property property : mapper.getProperties() ) {
@ -427,7 +428,8 @@ public class EntityBinder {
XClass classWithIdClass,
XClass compositeClass,
PropertyData baseInferredData,
AccessType propertyAccessor) {
AccessType propertyAccessor,
boolean isIdClass) {
final Component mapper = createMapper(
inheritanceStates,
persistentClass,
@ -436,7 +438,8 @@ public class EntityBinder {
classWithIdClass,
compositeClass,
baseInferredData,
propertyAccessor
propertyAccessor,
isIdClass
);
final Property mapperProperty = new Property();
mapperProperty.setName( NavigablePath.IDENTIFIER_MAPPER_PROPERTY );
@ -456,7 +459,8 @@ public class EntityBinder {
XClass classWithIdClass,
XClass compositeClass,
PropertyData baseInferredData,
AccessType propertyAccessor) {
AccessType propertyAccessor,
boolean isIdClass) {
final Component mapper = fillEmbeddable(
propertyHolder,
new PropertyPreloadedData(
@ -475,7 +479,8 @@ public class EntityBinder {
null,
null,
context,
inheritanceStates
inheritanceStates,
isIdClass
);
persistentClass.setIdentifierMapper( mapper );
@ -575,7 +580,8 @@ public class EntityBinder {
null,
null,
buildingContext,
inheritanceStates
inheritanceStates,
true
);
id.setKey( true );
if ( rootClass.getIdentifier() != null ) {