From e93d33be162bf2d49c98cc6c579105bc316851b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 4 Oct 2021 14:02:44 +0200 Subject: [PATCH] Have SessionFactory#getMetamodel() return a JpaMetamodel It just makes sense, since JpaMetamodel is Hibernate ORM's extension of jakarta.persistence.metamodel.Metamodel, and SessionFactory#getMetamodel() is Hibernate ORM's extension of EntityManager#getMetamodel(). --- .../main/java/org/hibernate/Metamodel.java | 12 +--- .../domain/internal/MappingMetamodelImpl.java | 56 +++++++++++++++++++ .../metamodel/spi/MetamodelImplementor.java | 18 ------ 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/Metamodel.java b/hibernate-core/src/main/java/org/hibernate/Metamodel.java index 853dea1361..730df0991a 100644 --- a/hibernate-core/src/main/java/org/hibernate/Metamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/Metamodel.java @@ -8,7 +8,6 @@ package org.hibernate; import jakarta.persistence.metamodel.EntityType; -import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; /** @@ -19,7 +18,7 @@ import org.hibernate.metamodel.model.domain.JpaMetamodel; * @see JpaMetamodel */ @Deprecated -public interface Metamodel extends jakarta.persistence.metamodel.Metamodel { +public interface Metamodel extends JpaMetamodel { /** * Access to the SessionFactory that this Metamodel instance is bound to. * @@ -35,15 +34,6 @@ public interface Metamodel extends jakarta.persistence.metamodel.Metamodel { return entity( entityName ); } - /** - * Access to an entity supporting Hibernate's entity-name feature - * - * @param entityName The entity-name - * - * @return The entity descriptor - */ - EntityDomainType entity(String entityName); - String getImportedClassName(String className); /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java index ea30065d2e..31ab4798d3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java @@ -41,6 +41,7 @@ import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.internal.EntityManagerMessageLogger; import org.hibernate.internal.HEMLogging; import org.hibernate.internal.util.collections.ArrayHelper; +import org.hibernate.jpa.spi.JpaCompliance; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Component; import org.hibernate.mapping.MappedSuperclass; @@ -471,6 +472,56 @@ public class MappingMetamodelImpl implements MappingMetamodel, MetamodelImplemen return jpaMetamodel.entity( entityName ); } + @Override + public EntityDomainType getHqlEntityReference(String entityName) { + return jpaMetamodel.getHqlEntityReference( entityName ); + } + + @Override + public EntityDomainType resolveHqlEntityReference(String entityName) { + return jpaMetamodel.resolveHqlEntityReference( entityName ); + } + + @Override + public void visitManagedTypes(Consumer> action) { + jpaMetamodel.visitManagedTypes( action ); + } + + @Override + public ManagedDomainType findManagedType(Class cls) { + return jpaMetamodel.findManagedType( cls ); + } + + @Override + public void visitEntityTypes(Consumer> action) { + jpaMetamodel.visitEntityTypes( action ); + } + + @Override + public EntityDomainType findEntityType(Class cls) { + return jpaMetamodel.findEntityType( cls ); + } + + @Override + public void visitRootEntityTypes(Consumer> action) { + jpaMetamodel.visitRootEntityTypes( action ); + } + + @Override + public void visitEmbeddables(Consumer> action) { + jpaMetamodel.visitEmbeddables( action ); + } + + @Override + public String qualifyImportableName(String queryName) { + return jpaMetamodel.qualifyImportableName( queryName ); + } + + @Override + public Map, Enum>> getAllowedEnumLiteralTexts() { + return jpaMetamodel.getAllowedEnumLiteralTexts(); + } + @Override public String getImportedClassName(String className) { throw new UnsupportedOperationException( ); @@ -616,6 +667,11 @@ public class MappingMetamodelImpl implements MappingMetamodel, MetamodelImplemen return jpaMetamodel.findEntityGraphsByJavaType( entityClass ); } + @Override + public JpaCompliance getJpaCompliance() { + return jpaMetamodel.getJpaCompliance(); + } + @Override public RootGraph findNamedGraph(String name) { return findEntityGraphByName( name ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java index 1b4a91c3d4..2519f65b7e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java @@ -18,9 +18,7 @@ import org.hibernate.Metamodel; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.metamodel.MappingMetamodel; -import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; @@ -110,18 +108,12 @@ public interface MetamodelImplementor extends MappingMetamodel, Metamodel { */ String[] getAllCollectionRoles(); - void addNamedEntityGraph(String graphName, RootGraphImplementor entityGraph); - /** * @deprecated Use {@link #addNamedEntityGraph(String, RootGraphImplementor)} instead. */ @Deprecated void addNamedEntityGraph(String graphName, EntityGraph entityGraph); - RootGraphImplementor findEntityGraphByName(String name); - - List> findEntityGraphsByJavaType(Class entityClass); - /** * @deprecated Use {@link #findEntityGraphsByJavaType(Class)} instead. */ @@ -136,16 +128,6 @@ public interface MetamodelImplementor extends MappingMetamodel, Metamodel { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Co-variant returns - - @Override - EntityDomainType entity(Class cls); - - @Override - ManagedDomainType managedType(Class cls); - - @Override - EmbeddableDomainType embeddable(Class cls); - @Override default EntityDomainType getEntityTypeByName(String entityName) { return entity( entityName );