From fcb8e323b0d1425dbb90789bdced88421e95059a Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 15 Dec 2022 13:34:40 -0600 Subject: [PATCH] HHH-15883 - Expose MappingMetamodel via unwrap from SessionFactory HHH-15884 - Clean-up EntityDiscriminatorMapping for API uses --- .../internal/PluralAttributeMappingImpl.java | 12 +++++++++++- .../AbstractCollectionPersister.java | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java index 79ea5a0336..095a5985bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java @@ -16,6 +16,7 @@ import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.generator.Generator; import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.Collection; import org.hibernate.mapping.IndexedConsumer; @@ -68,7 +69,6 @@ import org.hibernate.sql.results.graph.collection.internal.CollectionDomainResul import org.hibernate.sql.results.graph.collection.internal.DelayedCollectionFetch; import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch; import org.hibernate.sql.results.graph.collection.internal.SelectEagerCollectionFetch; -import org.hibernate.generator.Generator; import org.jboss.logging.Logger; @@ -80,7 +80,17 @@ public class PluralAttributeMappingImpl implements PluralAttributeMapping, FetchOptions { private static final Logger log = Logger.getLogger( PluralAttributeMappingImpl.class ); + /** + * Allows callback after creation of the attribute mapping. + * + * Support for the {@linkplain CollectionPersister collection}, + * {@linkplain CollectionPart element} and {@linkplain CollectionPart index} + * descriptors + */ public interface Aware { + /** + * Injects the created attribute mapping + */ void injectAttributeMapping(PluralAttributeMapping attributeMapping); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index fb9af49779..ab62f4b021 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -10,7 +10,6 @@ import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; @@ -52,6 +51,8 @@ import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SubselectFetch; +import org.hibernate.generator.Generator; +import org.hibernate.generator.InMemoryGenerator; import org.hibernate.id.IdentifierGenerator; import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.FilterHelper; @@ -75,6 +76,7 @@ import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Table; import org.hibernate.mapping.Value; import org.hibernate.metadata.CollectionMetadata; +import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.ForeignKeyDescriptor; import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper; @@ -127,8 +129,6 @@ import org.hibernate.sql.model.jdbc.JdbcMutationOperation; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.internal.ImmutableFetchList; import org.hibernate.sql.results.internal.SqlSelectionImpl; -import org.hibernate.generator.Generator; -import org.hibernate.generator.InMemoryGenerator; import org.hibernate.type.CollectionType; import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; @@ -1565,11 +1565,13 @@ public abstract class AbstractCollectionPersister // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // "mapping model" - // todo (6.0) : atm there is no way to get a `PluralAttributeMapping` reference except through - // its declaring `ManagedTypeMapping` attributes. this is a backhand way of getting access - // to it for use from the persister - - + /** + * Allows injection of the corresponding {@linkplain PluralAttributeMapping plural-attribute mapping}. + * + * @implNote Helps solve the chicken-egg problem of which to create first. Ultimately we could + * make this work in a similar fashion to how this works in the relationship between + * {@link org.hibernate.metamodel.mapping.EmbeddableMappingType} and {@link EmbeddableValuedModelPart}. + */ @Override public void injectAttributeMapping(PluralAttributeMapping attributeMapping) { this.attributeMapping = attributeMapping;