diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java index f63c3b3566..16d892cd0e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java @@ -54,8 +54,9 @@ import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.spi.TypeConfiguration; /** - * Base delegating implementation of the SessionFactory and SessionFactoryImplementor - * contracts for intended for easier implementation of SessionFactory. + * Base delegating implementation of the {@link SessionFactory} and + * {@link SessionFactoryImplementor} contracts for intended for easier + * implementation of {@link SessionFactory}. * * @author Steve Ebersole */ @@ -195,6 +196,16 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor, return delegate.getProperties(); } + @Override + public JdbcServices getJdbcServices() { + return delegate.getJdbcServices(); + } + + @Override + public SqlStringGenerationContext getSqlStringGenerationContext() { + return delegate.getSqlStringGenerationContext(); + } + @Deprecated public EntityPersister getEntityPersister(String entityName) throws MappingException { return delegate.getRuntimeMetamodels() @@ -223,16 +234,6 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor, return delegate.getMetamodel().collectionPersisters(); } - @Override - public JdbcServices getJdbcServices() { - return delegate.getJdbcServices(); - } - - @Override - public SqlStringGenerationContext getSqlStringGenerationContext() { - return delegate.getSqlStringGenerationContext(); - } - @Deprecated public String[] getImplementors(String className) throws MappingException { // for the time being, leave this calling `MetamodelImplementor` - nothing uses @@ -375,7 +376,7 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor, return delegate.getCriteriaBuilder(); } - @Override @SuppressWarnings("deprecation") + @Override @Deprecated public MetamodelImplementor getMetamodel() { return delegate.getMetamodel(); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java index a3f1671330..ed685b8658 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java @@ -169,7 +169,10 @@ public interface SessionFactoryImplementor // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // map these to Metamodel - @Override @SuppressWarnings("deprecation") + /** + * @deprecated no longer for internal use, use {@link #getMappingMetamodel()} or {@link #getJpaMetamodel()} + */ + @Override @Deprecated MetamodelImplementor getMetamodel(); RootGraphImplementor findEntityGraphByName(String name); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 613ae04d7f..aacfc63ff6 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -795,7 +795,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont if ( Tuple.class.equals(resultClass) ) { query.setTupleTransformer( new NativeQueryTupleTransformer() ); } - else if ( getFactory().getMetamodel().isEntityClass(resultClass) ) { + else if ( getFactory().getMappingMetamodel().isEntityClass(resultClass) ) { query.addEntity( "alias1", resultClass.getName(), LockMode.READ ); } return query; @@ -805,7 +805,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont public NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass, String tableAlias) { @SuppressWarnings("unchecked") NativeQueryImplementor query = createNativeQuery( sqlString ); - if ( getFactory().getMetamodel().isEntityClass(resultClass) ) { + if ( getFactory().getMappingMetamodel().isEntityClass(resultClass) ) { query.addEntity( tableAlias, resultClass.getName(), LockMode.READ ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 9924ec4b54..9c1ddcb622 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -95,7 +95,6 @@ import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl; import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor; import org.hibernate.metamodel.spi.RuntimeMetamodelsImplementor; import org.hibernate.query.BindableType; -import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.persister.entity.EntityPersister; @@ -515,7 +514,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { @Override public SessionBuilderImplementor withOptions() { - return new SessionBuilderImpl( this ); + return new SessionBuilderImpl<>( this ); } @Override @@ -602,7 +601,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { @Override public List> findEntityGraphsByType(Class entityClass) { - return (List) getMetamodel().findEntityGraphsByJavaType( entityClass ); + return (List) getJpaMetamodel().findEntityGraphsByJavaType( entityClass ); } // todo : (5.2) review synchronizationType, persistenceContextType, transactionType usage @@ -617,12 +616,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { assert status != Status.CLOSED; SessionBuilderImplementor builder = withOptions(); - if ( synchronizationType == SynchronizationType.SYNCHRONIZED ) { - builder.autoJoinTransactions( true ); - } - else { - builder.autoJoinTransactions( false ); - } + builder.autoJoinTransactions( synchronizationType == SynchronizationType.SYNCHRONIZED ); final Session session = builder.openSession(); if ( map != null ) { @@ -688,7 +682,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { @Override public RootGraphImplementor findEntityGraphByName(String name) { - return getMetamodel().findEntityGraphByName( name ); + return getJpaMetamodel().findEntityGraphByName( name ); } @Override @@ -952,7 +946,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { @Override public void addNamedEntityGraph(String graphName, EntityGraph entityGraph) { - getMetamodel().addNamedEntityGraph( graphName, (RootGraphImplementor) entityGraph ); + getMappingMetamodel().addNamedEntityGraph( graphName, (RootGraphImplementor) entityGraph ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 5eb26ede5d..533815aad3 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import jakarta.persistence.metamodel.Metamodel; import org.hibernate.CacheMode; import org.hibernate.ConnectionAcquisitionMode; import org.hibernate.Filter; @@ -114,7 +115,6 @@ import org.hibernate.loader.access.IdentifierLoadAccessImpl; import org.hibernate.loader.access.LoadAccessContext; import org.hibernate.loader.access.NaturalIdLoadAccessImpl; import org.hibernate.loader.access.SimpleNaturalIdLoadAccessImpl; -import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; import org.hibernate.procedure.ProcedureCall; @@ -334,7 +334,7 @@ public class SessionImpl @Override public SharedSessionBuilder sessionWithOptions() { - return new SharedSessionBuilderImpl( this ); + return new SharedSessionBuilderImpl<>( this ); } @Override @@ -2703,15 +2703,19 @@ public class SessionImpl } @Override - public MetamodelImplementor getMetamodel() { + public Metamodel getMetamodel() { checkOpen(); - return getFactory().getMetamodel(); + return getFactory().getJpaMetamodel(); } @Override public RootGraphImplementor createEntityGraph(Class rootType) { checkOpen(); - return new RootGraphImpl<>( null, getMetamodel().entity( rootType ), getEntityManagerFactory().getJpaMetamodel() ); + return new RootGraphImpl<>( + null, + getFactory().getJpaMetamodel().entity( rootType ), + getEntityManagerFactory().getJpaMetamodel() + ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index cc46c9e7bc..1c1b1de195 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -456,7 +456,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, expressibleType = (DomainType) typeConfiguration.resolveTupleType( sqmExpressions ); } else { - expressibleType = typeConfiguration.getSessionFactory().getMetamodel().embeddable( tupleType ); + expressibleType = typeConfiguration.getSessionFactory().getJpaMetamodel().embeddable( tupleType ); } return tuple( expressibleType, sqmExpressions ); } @@ -962,15 +962,9 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, public SqmExpression nullLiteral(Class resultClass) { final TypeConfiguration typeConfiguration = getTypeConfiguration(); final BasicType basicTypeForJavaType = typeConfiguration.getBasicTypeForJavaType( resultClass ); - final SqmExpressible sqmExpressible; - if ( basicTypeForJavaType == null ) { - sqmExpressible = typeConfiguration.getSessionFactory() - .getMetamodel() - .managedType( resultClass ); - } - else { - sqmExpressible = basicTypeForJavaType; - } + final SqmExpressible sqmExpressible = basicTypeForJavaType == null + ? typeConfiguration.getSessionFactory().getJpaMetamodel().managedType( resultClass ) + : basicTypeForJavaType; return new SqmLiteralNull<>(sqmExpressible, this ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/QueryBuilderTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/QueryBuilderTest.java index f38d02cfd3..8c0abed818 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/QueryBuilderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/QueryBuilderTest.java @@ -7,7 +7,6 @@ package org.hibernate.orm.test.jpa.criteria; import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.List; @@ -20,6 +19,7 @@ import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Root; import jakarta.persistence.criteria.SetJoin; import jakarta.persistence.metamodel.EntityType; +import jakarta.persistence.metamodel.Metamodel; import org.hibernate.dialect.CockroachDialect; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import org.hibernate.orm.test.jpa.metamodel.Address; @@ -35,7 +35,6 @@ import org.hibernate.orm.test.jpa.metamodel.Phone; import org.hibernate.orm.test.jpa.metamodel.Product; import org.hibernate.orm.test.jpa.metamodel.ShelfLife; import org.hibernate.orm.test.jpa.metamodel.Spouse; -import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl; import org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate; import org.hibernate.testing.FailureExpected; @@ -77,7 +76,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); + Metamodel mm = em.getMetamodel(); CriteriaQuery cquery = cb.createQuery( Integer.class ); Root product = cquery.from( Product.class ); @@ -120,7 +119,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { Phone phone3 = new Phone( "3", "555", "0003", address ); Phone phone4 = new Phone( "4", "555", "0004" ); - List phones = new ArrayList( 3 ); + List phones = new ArrayList<>( 3 ); phones.add( phone1 ); phones.add( phone2 ); phones.add( phone3 ); @@ -135,7 +134,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); + Metamodel mm = em.getMetamodel(); EntityType Phone_ = mm.entity( Phone.class ); CriteriaQuery cquery = cb.createQuery( Phone.class ); @@ -157,7 +156,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); + Metamodel mm = em.getMetamodel(); EntityType Product_ = mm.entity( Product.class ); // toFloat @@ -189,7 +188,6 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); CriteriaQuery cquery = cb.createQuery( Customer.class ); Root customer = cquery.from( Customer.class ); @@ -236,7 +234,6 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); CriteriaQuery dateQuery = cb.createQuery( java.sql.Date.class ); dateQuery.from( Customer.class ); @@ -328,7 +325,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { entityManager.persist( store ); final Book book = new Book(); - book.setStores( new HashSet<>( Arrays.asList( store ) ) ); + book.setStores( new HashSet<>( List.of(store) ) ); entityManager.persist( book ); } );