Make sure the SerializableJavaTypeDescriptor is never used for entities. Fix a wrong JDBC mapping causing problems converted attributes. Force IMMEDIATE fetch timing for many-to-one associations with NotFound.IGNORE

This commit is contained in:
Christian Beikov 2021-08-04 13:56:35 +02:00
parent 5da81c2263
commit 7b58e700db
7 changed files with 46 additions and 10 deletions

View File

@ -260,7 +260,7 @@ public class AttributeFactory {
final JavaTypeDescriptorRegistry registry = context.getTypeConfiguration() final JavaTypeDescriptorRegistry registry = context.getTypeConfiguration()
.getJavaTypeDescriptorRegistry(); .getJavaTypeDescriptorRegistry();
final JavaTypeDescriptor<Y> javaTypeDescriptor = registry.resolveDescriptor( embeddableClass ); final JavaTypeDescriptor<Y> javaTypeDescriptor = registry.resolveManagedTypeDescriptor( embeddableClass );
embeddableType = new EmbeddableTypeImpl<>( embeddableType = new EmbeddableTypeImpl<>(
javaTypeDescriptor, javaTypeDescriptor,

View File

@ -88,7 +88,7 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
.getJavaTypeDescriptorRegistry(); .getJavaTypeDescriptorRegistry();
final Class<?> mappedJavaType = bootDescriptor.getMappedClass(); final Class<?> mappedJavaType = bootDescriptor.getMappedClass();
this.mappedJtd = jtdRegistry.getDescriptor( mappedJavaType ); this.mappedJtd = jtdRegistry.resolveManagedTypeDescriptor( mappedJavaType );
final Class<?> proxyJavaType = bootDescriptor.getProxyInterface(); final Class<?> proxyJavaType = bootDescriptor.getProxyInterface();
if ( proxyJavaType != null ) { if ( proxyJavaType != null ) {

View File

@ -424,7 +424,7 @@ public class MetadataContext {
final JavaTypeDescriptorRegistry registry = getTypeConfiguration() final JavaTypeDescriptorRegistry registry = getTypeConfiguration()
.getJavaTypeDescriptorRegistry(); .getJavaTypeDescriptorRegistry();
final Class<?> componentClass = identifier.getComponentClass(); final Class<?> componentClass = identifier.getComponentClass();
final JavaTypeDescriptor<?> javaTypeDescriptor = registry.resolveDescriptor( componentClass ); final JavaTypeDescriptor<?> javaTypeDescriptor = registry.resolveManagedTypeDescriptor( componentClass );
final EmbeddableRepresentationStrategy representationStrategy = getTypeConfiguration() final EmbeddableRepresentationStrategy representationStrategy = getTypeConfiguration()
.getMetadataBuildingContext() .getMetadataBuildingContext()

View File

@ -144,7 +144,7 @@ public class BasicAttributeMapping
selectableMapping.getCustomReadExpression(), selectableMapping.getCustomReadExpression(),
selectableMapping.getCustomWriteExpression(), selectableMapping.getCustomWriteExpression(),
valueConverter, valueConverter,
selectableMapping.getJdbcMapping(), original.getJdbcMapping(),
declaringType, declaringType,
propertyAccess, propertyAccess,
valueGeneration valueGeneration

View File

@ -38,6 +38,7 @@ import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
import org.hibernate.mapping.IndexedCollection; import org.hibernate.mapping.IndexedCollection;
import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.ManyToOne;
import org.hibernate.mapping.OneToMany; import org.hibernate.mapping.OneToMany;
import org.hibernate.mapping.OneToOne; import org.hibernate.mapping.OneToOne;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
@ -1509,8 +1510,9 @@ public class MappingModelCreationHelper {
final FetchTiming fetchTiming; final FetchTiming fetchTiming;
if ( fetchStyle == FetchStyle.JOIN if ( fetchStyle == FetchStyle.JOIN
|| ( value instanceof OneToOne && value.isNullable() ) || !value.isLazy()
|| !( value ).isLazy() ) { || value instanceof OneToOne && value.isNullable()
|| value instanceof ManyToOne && value.isNullable() && ( (ManyToOne) value ).isIgnoreNotFound() ) {
fetchTiming = FetchTiming.IMMEDIATE; fetchTiming = FetchTiming.IMMEDIATE;
} }
else { else {

View File

@ -583,7 +583,7 @@ public class JpaMetamodelImpl implements JpaMetamodel {
else { else {
javaTypeDescriptor = context.getTypeConfiguration() javaTypeDescriptor = context.getTypeConfiguration()
.getJavaTypeDescriptorRegistry() .getJavaTypeDescriptorRegistry()
.getDescriptor( javaType ); .resolveManagedTypeDescriptor( javaType );
} }
final EntityTypeImpl<?> entityType = new EntityTypeImpl( final EntityTypeImpl<?> entityType = new EntityTypeImpl(
@ -636,10 +636,10 @@ public class JpaMetamodelImpl implements JpaMetamodel {
? null ? null
: locateOrBuildEntityType( superPersistentClass, context, typeConfiguration ); : locateOrBuildEntityType( superPersistentClass, context, typeConfiguration );
} }
final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration() final JavaTypeDescriptor<?> javaTypeDescriptor = context.getTypeConfiguration()
.getJavaTypeDescriptorRegistry() .getJavaTypeDescriptorRegistry()
.getDescriptor( mappedSuperclass.getMappedClass() ); .resolveManagedTypeDescriptor( mappedSuperclass.getMappedClass() );
final MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl( final MappedSuperclassTypeImpl<?> mappedSuperclassType = new MappedSuperclassTypeImpl(
javaTypeDescriptor, javaTypeDescriptor,
mappedSuperclass, mappedSuperclass,
superType, superType,

View File

@ -159,6 +159,40 @@ public class JavaTypeDescriptorRegistry implements JavaTypeDescriptorBaseline.Ba
); );
} }
@SuppressWarnings("unchecked")
public <J> JavaTypeDescriptor<J> resolveManagedTypeDescriptor(Type javaType) {
return resolveDescriptor(
javaType,
() -> {
final Class<J> javaTypeClass;
if ( javaType instanceof Class<?> ) {
javaTypeClass = (Class<J>) javaType;
}
else {
final ParameterizedType parameterizedType = (ParameterizedType) javaType;
javaTypeClass = (Class<J>) parameterizedType.getRawType();
}
final MutabilityPlan<J> mutabilityPlan;
final MutabilityPlan<J> determinedPlan = RegistryHelper.INSTANCE.determineMutabilityPlan(
javaType,
typeConfiguration
);
if ( determinedPlan != null ) {
mutabilityPlan = determinedPlan;
}
else {
mutabilityPlan = new MutableMutabilityPlan<J>() {
@Override
protected J deepCopyNotNull(J value) {
return value;
}
};
}
return new JavaTypeDescriptorBasicAdaptor<>( javaTypeClass, mutabilityPlan );
}
);
}
public JavaTypeDescriptor<?> resolveDynamicEntityDescriptor(String typeName) { public JavaTypeDescriptor<?> resolveDynamicEntityDescriptor(String typeName) {
return new DynamicModelJtd(); return new DynamicModelJtd();
} }