From 31f495c9d5d80b6bbd8f29c04b0f3f414b3e5074 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 14 Jun 2024 08:47:39 -0500 Subject: [PATCH] Rebase main -> 7.0 fixups --- .../InFlightMetadataCollectorImpl.java | 33 +++----------- .../boot/model/internal/EmbeddableBinder.java | 10 +++-- .../internal/FilterDefAnnotation.java | 43 +++++++++++++------ .../internal/GlobalRegistrationsImpl.java | 5 ++- .../models/spi/FilterDefRegistration.java | 9 +++- .../internal/StatelessSessionImpl.java | 13 ++++-- .../entity/AbstractEntityPersister.java | 12 ------ .../internal/EmbeddableInitializerImpl.java | 1 + .../org/hibernate/xsd/mapping/mapping-7.0.xsd | 1 + 9 files changed, 67 insertions(+), 60 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java index 0d99f9bcc6..cec9104418 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java @@ -1333,25 +1333,25 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, } private static AnnotatedClassType getAnnotatedClassType(ClassDetails clazz) { - if ( clazz.isAnnotationPresent( Entity.class ) ) { - if ( clazz.isAnnotationPresent( Embeddable.class ) ) { + if ( clazz.hasDirectAnnotationUsage( Entity.class ) ) { + if ( clazz.hasDirectAnnotationUsage( Embeddable.class ) ) { throw new AnnotationException( "Invalid class annotated both '@Entity' and '@Embeddable': '" + clazz.getName() + "'" ); } - else if ( clazz.isAnnotationPresent( jakarta.persistence.MappedSuperclass.class ) ) { + else if ( clazz.hasDirectAnnotationUsage( jakarta.persistence.MappedSuperclass.class ) ) { throw new AnnotationException( "Invalid class annotated both '@Entity' and '@MappedSuperclass': '" + clazz.getName() + "'" ); } return AnnotatedClassType.ENTITY; } - else if ( clazz.isAnnotationPresent( Embeddable.class ) ) { - if ( clazz.isAnnotationPresent( jakarta.persistence.MappedSuperclass.class ) ) { + else if ( clazz.hasDirectAnnotationUsage( Embeddable.class ) ) { + if ( clazz.hasDirectAnnotationUsage( jakarta.persistence.MappedSuperclass.class ) ) { throw new AnnotationException( "Invalid class annotated both '@Embeddable' and '@MappedSuperclass': '" + clazz.getName() + "'" ); } return AnnotatedClassType.EMBEDDABLE; } - else if ( clazz.isAnnotationPresent( jakarta.persistence.MappedSuperclass.class ) ) { + else if ( clazz.hasDirectAnnotationUsage( jakarta.persistence.MappedSuperclass.class ) ) { return AnnotatedClassType.MAPPED_SUPERCLASS; } - else if ( clazz.isAnnotationPresent( Imported.class ) ) { + else if ( clazz.hasDirectAnnotationUsage( Imported.class ) ) { return AnnotatedClassType.IMPORTED; } else { @@ -1359,13 +1359,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, } } - @Override - public AnnotatedClassType addClassType(ClassDetails classDetails) { - final AnnotatedClassType type = getAnnotatedClassType2( classDetails ); - annotatedClassTypeMap.put( classDetails.getName(), type ); - return type; - } - private static AnnotatedClassType getAnnotatedClassType2(ClassDetails classDetails) { if ( classDetails.hasDirectAnnotationUsage( Entity.class ) ) { return AnnotatedClassType.ENTITY; @@ -1384,18 +1377,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, } } - @Override - public AnnotatedClassType getClassType(ClassDetails classDetails) { - final AnnotatedClassType type = annotatedClassTypeMap.get( classDetails.getName() ); - if ( type == null ) { - return addClassType( classDetails ); - } - else { - return type; - } - } - - @Override public void addMappedSuperclass(Class type, MappedSuperclass mappedSuperclass) { if ( mappedSuperClasses == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java index c3a1337e4c..45ee381fef 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java @@ -418,13 +418,15 @@ public class EmbeddableBinder { ); } + final Map subclassToSuperclass = component.isPolymorphic() ? new HashMap<>() : null; final TypeDetails annotatedType = inferredData.getPropertyType(); final List classElements = collectClassElements( propertyAccessor, context, returnedClassOrElement, annotatedType, - isIdClass + isIdClass, + subclassToSuperclass ); if ( component.isPolymorphic() ) { @@ -637,9 +639,9 @@ public class EmbeddableBinder { new PropertyContainer( returnedClassOrElement, annotatedClass, propertyAccessor ); addElementsOfClass( classElements, container, context); //add elements of the embeddable's mapped superclasses - ClassDetails subClass = returnedClassOrElement; - XClass superClass; - while ( isValidSuperclass( superClass = subclass.getSuperclass(), isIdClass ) ) { + ClassDetails subclass = returnedClassOrElement; + ClassDetails superClass; + while ( isValidSuperclass( superClass = subclass.getSuperClass(), isIdClass ) ) { //FIXME: proper support of type variables incl var resolved at upper levels final PropertyContainer superContainer = new PropertyContainer( superClass, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefAnnotation.java index 0f03c4a94a..671ea58e8c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefAnnotation.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefAnnotation.java @@ -22,8 +22,9 @@ import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkV public class FilterDefAnnotation implements FilterDef { private String name; private String defaultCondition; - private org.hibernate.annotations.ParamDef[] parameters; private boolean autoEnabled; + private boolean applyToLoadByKey; + private org.hibernate.annotations.ParamDef[] parameters; /** * Used in creating dynamic annotation instances (e.g. from XML) @@ -40,8 +41,9 @@ public class FilterDefAnnotation implements FilterDef { public FilterDefAnnotation(FilterDef annotation, SourceModelBuildingContext modelContext) { this.name = annotation.name(); this.defaultCondition = annotation.defaultCondition(); - this.parameters = extractJdkValue( annotation, HibernateAnnotations.FILTER_DEF, "parameters", modelContext ); this.autoEnabled = annotation.autoEnabled(); + this.applyToLoadByKey = annotation.applyToLoadByKey();; + this.parameters = extractJdkValue( annotation, HibernateAnnotations.FILTER_DEF, "parameters", modelContext ); } /** @@ -55,13 +57,19 @@ public class FilterDefAnnotation implements FilterDef { "defaultCondition", modelContext ); - this.parameters = extractJandexValue( annotation, HibernateAnnotations.FILTER_DEF, "parameters", modelContext ); this.autoEnabled = extractJandexValue( annotation, HibernateAnnotations.FILTER_DEF, "autoEnabled", modelContext ); + this.applyToLoadByKey = extractJandexValue( + annotation, + HibernateAnnotations.FILTER_DEF, + "applyToLoadByKey", + modelContext + ); + this.parameters = extractJandexValue( annotation, HibernateAnnotations.FILTER_DEF, "parameters", modelContext ); } @Override @@ -89,16 +97,6 @@ public class FilterDefAnnotation implements FilterDef { } - @Override - public org.hibernate.annotations.ParamDef[] parameters() { - return parameters; - } - - public void parameters(org.hibernate.annotations.ParamDef[] value) { - this.parameters = value; - } - - @Override public boolean autoEnabled() { return autoEnabled; @@ -109,4 +107,23 @@ public class FilterDefAnnotation implements FilterDef { } + @Override + public boolean applyToLoadByKey() { + return applyToLoadByKey; + } + + public void applyToLoadByKey(boolean value) { + this.applyToLoadByKey = value; + } + + @Override + public org.hibernate.annotations.ParamDef[] parameters() { + return parameters; + } + + public void parameters(org.hibernate.annotations.ParamDef[] value) { + this.parameters = value; + } + + } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java index cb41b6e3d1..623a4a86d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java @@ -545,6 +545,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { usage.name(), usage.defaultCondition(), usage.autoEnabled(), + usage.applyToLoadByKey(), paramJdbcMappings, parameterResolvers ); @@ -597,6 +598,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { filterDefinition.getName(), filterDefinition.getDefaultCondition(), filterDefinition.isAutoEnabled(), + filterDefinition.isApplyToLoadByKey(), paramJdbcMappings, parameterResolvers ); @@ -607,6 +609,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { String name, String defaultCondition, boolean autoEnabled, + boolean applyToLoadByKey, Map parameterTypes, Map parameterResolvers) { if ( filterDefRegistrations == null ) { @@ -615,7 +618,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { final FilterDefRegistration previousEntry = filterDefRegistrations.put( name, - new FilterDefRegistration( name, defaultCondition, autoEnabled, parameterTypes, parameterResolvers ) + new FilterDefRegistration( name, defaultCondition, autoEnabled, applyToLoadByKey, parameterTypes, parameterResolvers ) ); if ( previousEntry != null ) { // legacy code simply allows the collision overwriting the previous diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/spi/FilterDefRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/FilterDefRegistration.java index 483e94c50f..834c1d5726 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/spi/FilterDefRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/FilterDefRegistration.java @@ -32,7 +32,7 @@ public class FilterDefRegistration { private final String name; private final String defaultCondition; private final boolean autoEnabled; - + private final boolean applyToLoadByKey; private final Map parameterTypes; private final Map parameterResolvers; @@ -40,11 +40,13 @@ public class FilterDefRegistration { String name, String defaultCondition, boolean autoEnabled, + boolean applyToLoadByKey, Map parameterTypes, Map parameterResolvers) { this.name = name; this.defaultCondition = defaultCondition; this.autoEnabled = autoEnabled; + this.applyToLoadByKey = applyToLoadByKey; this.parameterTypes = parameterTypes; this.parameterResolvers = parameterResolvers; } @@ -61,6 +63,10 @@ public class FilterDefRegistration { return autoEnabled; } + public boolean isApplyToLoadByKey() { + return applyToLoadByKey; + } + public Map getParameterTypes() { return parameterTypes; } @@ -104,6 +110,7 @@ public class FilterDefRegistration { getName(), getDefaultCondition(), isAutoEnabled(), + isApplyToLoadByKey(), parameterJdbcMappings, parameterResolvers ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java index 080d6c3ab8..15afe2c547 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -132,12 +132,19 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen } final Generator generator = persister.getGenerator(); if ( !generator.generatedOnExecution( entity, this ) ) { - id = ( (BeforeExecutionGenerator) generator).generate( this, entity, null, INSERT ); + if ( generator.generatesOnInsert() ) { + id = ( (BeforeExecutionGenerator) generator).generate( this, entity, null, INSERT ); + } + else { + id = persister.getIdentifier( entity, this ); + if ( id == null ) { + throw new IdentifierGenerationException( "Identifier of entity '" + persister.getEntityName() + "' must be manually assigned before calling 'insert()'" ); + } + } if ( firePreInsert(entity, id, state, persister) ) { return id; } - getInterceptor() - .onInsert( entity, id, state, persister.getPropertyNames(), persister.getPropertyTypes() ); + getInterceptor().onInsert( entity, id, state, persister.getPropertyNames(), persister.getPropertyTypes() ); persister.getInsertCoordinator().insert( entity, id, state, this ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index ae757aed69..9169bf97c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -754,18 +754,6 @@ public abstract class AbstractEntityPersister subclassPropertyFetchModeClosure[j++] = fetchMode; } - propertyDefinedOnSubclass = toBooleanArray( definedBySubclass ); - - // Handle any filters applied to the class level - filterHelper = isNotEmpty( persistentClass.getFilters() ) ? new FilterHelper( - persistentClass.getFilters(), - getEntityNameByTableNameMap( - persistentClass, - factory.getSqlStringGenerationContext() - ), - factory - ) : null; - useReferenceCacheEntries = shouldUseReferenceCacheEntries( creationContext.getSessionFactoryOptions() ); useShallowQueryCacheLayout = shouldUseShallowCacheLayout( persistentClass.getQueryCacheLayout(), diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableInitializerImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableInitializerImpl.java index 77c738ca90..f77d77b0fc 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableInitializerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableInitializerImpl.java @@ -21,6 +21,7 @@ import org.hibernate.metamodel.spi.EmbeddableInstantiator; import org.hibernate.metamodel.spi.ValueAccess; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.property.access.spi.Setter; +import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; import org.hibernate.spi.NavigablePath; import org.hibernate.sql.results.graph.AssemblerCreationState; diff --git a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd index 87fe6306ee..ff66255c1d 100644 --- a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd @@ -2798,6 +2798,7 @@ +