diff --git a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java index 622aa049d6..b4c67483a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java @@ -8,20 +8,21 @@ package org.hibernate; import java.io.Serializable; import java.sql.Connection; -import java.util.Map; +import java.util.List; import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; import javax.naming.Referenceable; -import jakarta.persistence.EntityManagerFactory; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.engine.spi.FilterDefinition; -import org.hibernate.jpa.HibernateEntityManagerFactory; import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.CollectionMetadata; import org.hibernate.stat.Statistics; +import jakarta.persistence.EntityGraph; +import jakarta.persistence.EntityManagerFactory; + /** * The main contract here is the creation of {@link Session} instances. Usually * an application has a single {@link SessionFactory} instance and threads @@ -38,7 +39,7 @@ import org.hibernate.stat.Statistics; * @author Gavin King * @author Steve Ebersole */ -public interface SessionFactory extends EntityManagerFactory, HibernateEntityManagerFactory, Referenceable, Serializable, java.io.Closeable { +public interface SessionFactory extends EntityManagerFactory, Referenceable, Serializable, java.io.Closeable { /** * Get the special options used to build the factory. * @@ -240,6 +241,13 @@ public interface SessionFactory extends EntityManagerFactory, HibernateEntityMan @Override Cache getCache(); + /** + * Get all EntityGraphs registered for a particular entity type + * + * @see #addNamedEntityGraph + */ + List> findEntityGraphsByType(Class entityClass); + /** * Obtain a set of the names of all filters defined on this SessionFactory. * diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/ExternalSessionFactoryConfig.java b/hibernate-core/src/main/java/org/hibernate/cfg/ExternalSessionFactoryConfig.java deleted file mode 100644 index 9b9f97e91b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/cfg/ExternalSessionFactoryConfig.java +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.cfg; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.hibernate.internal.util.config.ConfigurationHelper; - -/** - * Defines support for various externally configurable SessionFactory(s), - * for example, the JCA adapter. - * - * @author Steve Ebersole - */ -public abstract class ExternalSessionFactoryConfig { - private String mapResources; - private String dialect; - private String defaultSchema; - private String defaultCatalog; - private String maximumFetchDepth; - private String jdbcFetchSize; - private String jdbcBatchSize; - private String batchVersionedDataEnabled; - private String jdbcScrollableResultSetEnabled; - private String getGeneratedKeysEnabled; - private String streamsForBinaryEnabled; - private String reflectionOptimizationEnabled; - private String showSqlEnabled; - private String commentsEnabled; - private String cacheRegionFactory; - private String cacheProviderConfig; - private String cacheRegionPrefix; - private String secondLevelCacheEnabled; - private String minimalPutsEnabled; - private String queryCacheEnabled; - - private Map additionalProperties; - private Set excludedPropertyNames = new HashSet(); - - protected Set getExcludedPropertyNames() { - return excludedPropertyNames; - } - - public final String getMapResources() { - return mapResources; - } - - public final void setMapResources(String mapResources) { - this.mapResources = mapResources; - } - - public void addMapResource(String mapResource) { - if ( mapResources==null || mapResources.length()==0 ) { - mapResources = mapResource.trim(); - } - else { - mapResources += ", " + mapResource.trim(); - } - } - - public final String getDialect() { - return dialect; - } - - public final void setDialect(String dialect) { - this.dialect = dialect; - } - - public final String getDefaultSchema() { - return defaultSchema; - } - - public final void setDefaultSchema(String defaultSchema) { - this.defaultSchema = defaultSchema; - } - - public final String getDefaultCatalog() { - return defaultCatalog; - } - - public final void setDefaultCatalog(String defaultCatalog) { - this.defaultCatalog = defaultCatalog; - } - - public final String getMaximumFetchDepth() { - return maximumFetchDepth; - } - - public final void setMaximumFetchDepth(String maximumFetchDepth) { - verifyInt( maximumFetchDepth ); - this.maximumFetchDepth = maximumFetchDepth; - } - - public final String getJdbcFetchSize() { - return jdbcFetchSize; - } - - public final void setJdbcFetchSize(String jdbcFetchSize) { - verifyInt( jdbcFetchSize ); - this.jdbcFetchSize = jdbcFetchSize; - } - - public final String getJdbcBatchSize() { - return jdbcBatchSize; - } - - public final void setJdbcBatchSize(String jdbcBatchSize) { - verifyInt( jdbcBatchSize ); - this.jdbcBatchSize = jdbcBatchSize; - } - - public final String getBatchVersionedDataEnabled() { - return batchVersionedDataEnabled; - } - - public final void setBatchVersionedDataEnabled(String batchVersionedDataEnabled) { - this.batchVersionedDataEnabled = batchVersionedDataEnabled; - } - - public final String getJdbcScrollableResultSetEnabled() { - return jdbcScrollableResultSetEnabled; - } - - public final void setJdbcScrollableResultSetEnabled(String jdbcScrollableResultSetEnabled) { - this.jdbcScrollableResultSetEnabled = jdbcScrollableResultSetEnabled; - } - - public final String getGetGeneratedKeysEnabled() { - return getGeneratedKeysEnabled; - } - - public final void setGetGeneratedKeysEnabled(String getGeneratedKeysEnabled) { - this.getGeneratedKeysEnabled = getGeneratedKeysEnabled; - } - - public final String getStreamsForBinaryEnabled() { - return streamsForBinaryEnabled; - } - - public final void setStreamsForBinaryEnabled(String streamsForBinaryEnabled) { - this.streamsForBinaryEnabled = streamsForBinaryEnabled; - } - - public final String getReflectionOptimizationEnabled() { - return reflectionOptimizationEnabled; - } - - public final void setReflectionOptimizationEnabled(String reflectionOptimizationEnabled) { - this.reflectionOptimizationEnabled = reflectionOptimizationEnabled; - } - - public final String getShowSqlEnabled() { - return showSqlEnabled; - } - - public final void setShowSqlEnabled(String showSqlEnabled) { - this.showSqlEnabled = showSqlEnabled; - } - - public final String getCommentsEnabled() { - return commentsEnabled; - } - - public final void setCommentsEnabled(String commentsEnabled) { - this.commentsEnabled = commentsEnabled; - } - - public final String getSecondLevelCacheEnabled() { - return secondLevelCacheEnabled; - } - - public final void setSecondLevelCacheEnabled(String secondLevelCacheEnabled) { - this.secondLevelCacheEnabled = secondLevelCacheEnabled; - } - - public final String getCacheRegionFactory() { - return cacheRegionFactory; - } - - public final void setCacheRegionFactory(String cacheRegionFactory) { - this.cacheRegionFactory = cacheRegionFactory; - } - - public String getCacheProviderConfig() { - return cacheProviderConfig; - } - - public void setCacheProviderConfig(String cacheProviderConfig) { - this.cacheProviderConfig = cacheProviderConfig; - } - - public final String getCacheRegionPrefix() { - return cacheRegionPrefix; - } - - public final void setCacheRegionPrefix(String cacheRegionPrefix) { - this.cacheRegionPrefix = cacheRegionPrefix; - } - - public final String getMinimalPutsEnabled() { - return minimalPutsEnabled; - } - - public final void setMinimalPutsEnabled(String minimalPutsEnabled) { - this.minimalPutsEnabled = minimalPutsEnabled; - } - - public final String getQueryCacheEnabled() { - return queryCacheEnabled; - } - - public final void setQueryCacheEnabled(String queryCacheEnabled) { - this.queryCacheEnabled = queryCacheEnabled; - } - - public final void addAdditionalProperty(String name, String value) { - if ( !getExcludedPropertyNames().contains( name ) ) { - if ( additionalProperties == null ) { - additionalProperties = new HashMap(); - } - additionalProperties.put( name, value ); - } - } - - protected final Configuration buildConfiguration() { - - Configuration cfg = new Configuration().setProperties( buildProperties() ); - - - String[] mappingFiles = ConfigurationHelper.toStringArray( mapResources, " ,\n\t\r\f" ); - for ( String mappingFile : mappingFiles ) { - cfg.addResource( mappingFile ); - } - - return cfg; - } - - protected final Properties buildProperties() { - Properties props = new Properties(); - setUnlessNull( props, Environment.DIALECT, dialect ); - setUnlessNull( props, Environment.DEFAULT_SCHEMA, defaultSchema ); - setUnlessNull( props, Environment.DEFAULT_CATALOG, defaultCatalog ); - setUnlessNull( props, Environment.MAX_FETCH_DEPTH, maximumFetchDepth ); - setUnlessNull( props, Environment.STATEMENT_FETCH_SIZE, jdbcFetchSize ); - setUnlessNull( props, Environment.STATEMENT_BATCH_SIZE, jdbcBatchSize ); - setUnlessNull( props, Environment.BATCH_VERSIONED_DATA, batchVersionedDataEnabled ); - setUnlessNull( props, Environment.USE_SCROLLABLE_RESULTSET, jdbcScrollableResultSetEnabled ); - setUnlessNull( props, Environment.USE_GET_GENERATED_KEYS, getGeneratedKeysEnabled ); - setUnlessNull( props, Environment.USE_STREAMS_FOR_BINARY, streamsForBinaryEnabled ); - setUnlessNull( props, Environment.USE_REFLECTION_OPTIMIZER, reflectionOptimizationEnabled ); - setUnlessNull( props, Environment.SHOW_SQL, showSqlEnabled ); - setUnlessNull( props, Environment.USE_SQL_COMMENTS, commentsEnabled ); - setUnlessNull( props, Environment.CACHE_REGION_FACTORY, cacheRegionFactory ); - setUnlessNull( props, Environment.CACHE_PROVIDER_CONFIG, cacheProviderConfig ); - setUnlessNull( props, Environment.CACHE_REGION_PREFIX, cacheRegionPrefix ); - setUnlessNull( props, Environment.USE_MINIMAL_PUTS, minimalPutsEnabled ); - setUnlessNull( props, Environment.USE_SECOND_LEVEL_CACHE, secondLevelCacheEnabled ); - setUnlessNull( props, Environment.USE_QUERY_CACHE, queryCacheEnabled ); - - Map extraProperties = getExtraProperties(); - if ( extraProperties != null ) { - addAll( props, extraProperties ); - } - - if ( additionalProperties != null ) { - addAll( props, additionalProperties ); - } - - return props; - } - - protected void addAll( Properties target, Map source ) { - Iterator itr = source.entrySet().iterator(); - while ( itr.hasNext() ) { - final Map.Entry entry = ( Map.Entry ) itr.next(); - final String propertyName = ( String ) entry.getKey(); - final String propertyValue = ( String ) entry.getValue(); - if ( propertyName != null && propertyValue != null ) { - // Make sure we don't override previous set values - if ( !target.keySet().contains( propertyName ) ) { - if ( !getExcludedPropertyNames().contains( propertyName) ) { - target.put( propertyName, propertyValue ); - } - } - } - } - } - - protected Map getExtraProperties() { - return null; - } - - private void setUnlessNull(Properties props, String key, String value) { - if ( value != null ) { - props.setProperty( key, value ); - } - } - - private void verifyInt(String value) { - if ( value != null ) { - Integer.parseInt( value ); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/classic/Lifecycle.java b/hibernate-core/src/main/java/org/hibernate/classic/Lifecycle.java index 991ce73d49..3d3074e264 100644 --- a/hibernate-core/src/main/java/org/hibernate/classic/Lifecycle.java +++ b/hibernate-core/src/main/java/org/hibernate/classic/Lifecycle.java @@ -41,6 +41,15 @@ import java.io.Serializable; * to the object, except when identity column key generation is used. * * @see CallbackException + * @see jakarta.persistence.EntityListeners + * @see jakarta.persistence.PrePersist + * @see jakarta.persistence.PreRemove + * @see jakarta.persistence.PreUpdate + * @see jakarta.persistence.PostLoad + * @see jakarta.persistence.PostPersist + * @see jakarta.persistence.PostRemove + * @see jakarta.persistence.PostUpdate + * * @author Gavin King */ public interface Lifecycle { diff --git a/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManager.java b/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManager.java deleted file mode 100644 index a54d6de9a6..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManager.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.ejb; - -/** - * @deprecated Use {@link org.hibernate.jpa.HibernateEntityManager} instead - */ -@Deprecated -public interface HibernateEntityManager { -} diff --git a/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java b/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java deleted file mode 100644 index d41b73dea1..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.ejb; - -/** - * @deprecated Use {@link org.hibernate.jpa.HibernateEntityManagerFactory} instead - */ -@Deprecated -public interface HibernateEntityManagerFactory extends org.hibernate.jpa.HibernateEntityManagerFactory { -} 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 be2d4d24ab..d7bfc8a57a 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 @@ -251,8 +251,7 @@ public interface SessionFactoryImplementor @Override MetamodelImplementor getMetamodel(); - @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) default List> findEntityGraphsByType(Class entityClass) { return (List) findEntityGraphsByJavaType( entityClass ); } 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 8b05106ccf..b7a5adc9ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -2213,9 +2213,6 @@ public class SessionImpl return getHibernateFlushMode() != FlushMode.MANUAL; } - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // HibernateEntityManager impl - @Override public SessionImplementor getSession() { return this; diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/HibernateEntityManager.java b/hibernate-core/src/main/java/org/hibernate/jpa/HibernateEntityManager.java deleted file mode 100644 index 3712934b6b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jpa/HibernateEntityManager.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.jpa; - -import jakarta.persistence.EntityManager; - -import org.hibernate.Session; -import org.hibernate.query.QueryProducer; - -/** - * Additional contract for Hibernate implementations of {@link jakarta.persistence.EntityManager} providing access to various Hibernate - * specific functionality. - * - * @author Gavin King - * - * @deprecated (since 5.2) Use Session (or SessionImplementor), as it now extends EntityManager directly - */ -@Deprecated -public interface HibernateEntityManager extends EntityManager, QueryProducer { - /** - * Retrieve a reference to the Hibernate {@link Session} used by this {@link jakarta.persistence.EntityManager}. - * - * @return The session - */ - Session getSession(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/HibernateEntityManagerFactory.java b/hibernate-core/src/main/java/org/hibernate/jpa/HibernateEntityManagerFactory.java deleted file mode 100644 index 6b5fd06f4f..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jpa/HibernateEntityManagerFactory.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.jpa; - -import java.io.Serializable; -import java.util.List; - -import org.hibernate.Metamodel; -import org.hibernate.boot.spi.SessionFactoryOptions; -import org.hibernate.engine.spi.SessionFactoryImplementor; - -import jakarta.persistence.EntityGraph; -import jakarta.persistence.EntityManagerFactory; -import jakarta.persistence.metamodel.EntityType; - -/** - * Contract giving access to the underlying {@link org.hibernate.SessionFactory} from an {@link jakarta.persistence.EntityManagerFactory} - * - * @author Gavin King - * - * @deprecated (since 5.2) Use SessionFactory (or SessionFactoryImplementor) as it now extends EntityManagerFactory directly - */ -@Deprecated -public interface HibernateEntityManagerFactory extends EntityManagerFactory, Serializable { - - /** - * Find all {@code EntityGraph}s associated with a given entity type. - * - * @param entityClass the entity type for which to find all {@code EntityGraph}s. - * - * @return A list of {@code EntityGraph} instances associated with the given entity type. The empty list is - * returned in case there are not entity graphs. - */ - List> findEntityGraphsByType(Class entityClass); - - @Override - Metamodel getMetamodel(); - - /** - * Obtain the underlying Hibernate SessionFactory. - * - * @return The underlying Hibernate SessionFactory - * - * @deprecated The expectation is that SessionFactory implementors also implement - * EntityManagerFactory; so this call really should just return {@code this}. As an - * alternative, call {@link EntityManagerFactory#unwrap} passing {@code SessionFactoryImplementor.class} - * - */ - @Deprecated - default SessionFactoryImplementor getSessionFactory() { - return (SessionFactoryImplementor) this; - } - - /** - * Returns the name of the factory. The name is either can be specified via the property hibernate.ejb.entitymanager_factory_name. - * If the property is not set the persistence unit name is used. If persistence unit name is not available, a unique - * name will be generated. - * - * @return the name of the factory. - * - * @deprecated - no longer necessary. all references can be directly replaced with - * calls to {@link SessionFactoryOptions#getSessionFactoryName()} - * via {@link #getSessionFactory()} -> {@link SessionFactoryImplementor#getSessionFactoryOptions()} - */ - @Deprecated - default String getEntityManagerFactoryName() { - return getSessionFactory().getName(); - } - - /** - * Find an entity type by name - * - * @param entityName entity name - * - * @return the {@code EntityType} for the specified name - * - * @deprecated Use org.hibernate.MetamodelImplementor#getEntityTypeByName instead. - */ - @Deprecated - default EntityType getEntityTypeByName(String entityName) { - final EntityType entityType = getMetamodel().getEntityTypeByName( entityName ); - if ( entityType == null ) { - throw new IllegalArgumentException( "[" + entityName + "] did not refer to EntityType" ); - } - return entityType; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/scanning/PackagedEntityManagerTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/scanning/PackagedEntityManagerTest.java index 236f8c4da9..5cdbb3a15a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/scanning/PackagedEntityManagerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/scanning/PackagedEntityManagerTest.java @@ -10,17 +10,13 @@ import java.io.File; import java.util.HashMap; import java.util.HashSet; import java.util.Properties; -import jakarta.persistence.EntityManager; -import jakarta.persistence.EntityManagerFactory; -import jakarta.persistence.Persistence; -import jakarta.persistence.PersistenceException; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.AvailableSettings; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.spi.EventType; import org.hibernate.internal.util.ConfigHelper; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.jpa.HibernateEntityManagerFactory; import org.hibernate.orm.test.jpa.Distributor; import org.hibernate.orm.test.jpa.Item; import org.hibernate.orm.test.jpa.pack.cfgxmlpar.Morito; @@ -47,6 +43,11 @@ import org.hibernate.testing.transaction.TransactionUtil; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; +import jakarta.persistence.Persistence; +import jakarta.persistence.PersistenceException; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; @@ -373,7 +374,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { res.setName( "Bruce" ); item.setDistributors( new HashSet() ); item.getDistributors().add( res ); - Statistics stats = ( (HibernateEntityManagerFactory) emf ).getSessionFactory().getStatistics(); + Statistics stats = emf.unwrap( SessionFactory.class ).getStatistics(); stats.clear(); stats.setStatisticsEnabled( true ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EntityManagerFactoryUnwrapTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EntityManagerFactoryUnwrapTest.java index a9dc6e74f5..b818afa386 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EntityManagerFactoryUnwrapTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EntityManagerFactoryUnwrapTest.java @@ -9,20 +9,18 @@ package org.hibernate.orm.test.jpa; -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceException; - import org.hibernate.SessionFactory; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.SessionFactoryImpl; -import org.hibernate.jpa.HibernateEntityManagerFactory; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.Jpa; - import org.junit.jupiter.api.Test; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceException; + import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; @@ -45,21 +43,6 @@ public class EntityManagerFactoryUnwrapTest { assertNotNull( sessionFactoryImplementor, "Unwrapping to SPI class SessionFactoryImplementor should be ok" ); } - @Test - public void testEntityManagerCanBeUnwrappedToDeprecatedHibernateEntityManagerFactory(EntityManagerFactoryScope scope) { - HibernateEntityManagerFactory hibernateEntityManagerFactory = scope.getEntityManagerFactory().unwrap( - HibernateEntityManagerFactory.class - ); - assertNotNull( hibernateEntityManagerFactory, "Unwrapping to SPI class HibernateEntityManagerFactory should be ok" ); - } - - @Test - public void testEntityManagerCanBeUnwrappedToHibernateEntityManagerFactory(EntityManagerFactoryScope scope) { - HibernateEntityManagerFactory hibernateEntityManagerFactory = scope.getEntityManagerFactory().unwrap( - HibernateEntityManagerFactory.class ); - assertNotNull( hibernateEntityManagerFactory, "Unwrapping to SPI class HibernateEntityManagerFactory should be ok" ); - } - @Test public void testEntityManagerCanBeUnwrappedToObject(EntityManagerFactoryScope scope) { Object object = scope.getEntityManagerFactory().unwrap( Object.class ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EntityManagerTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EntityManagerTest.java index ab7a930e1f..ce2f5fc598 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EntityManagerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EntityManagerTest.java @@ -14,6 +14,19 @@ import java.io.ObjectOutputStream; import java.util.HashMap; import java.util.HashSet; import java.util.Map; + +import org.hibernate.FlushMode; +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Environment; +import org.hibernate.jpa.QueryHints; +import org.hibernate.stat.Statistics; + +import org.hibernate.testing.TestForIssue; +import org.junit.Test; + import jakarta.persistence.EntityExistsException; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityNotFoundException; @@ -21,17 +34,6 @@ import jakarta.persistence.FlushModeType; import jakarta.persistence.PersistenceException; import jakarta.persistence.Query; -import org.hibernate.FlushMode; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.Environment; -import org.hibernate.jpa.HibernateEntityManagerFactory; -import org.hibernate.jpa.QueryHints; -import org.hibernate.stat.Statistics; -import org.hibernate.testing.TestForIssue; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -126,7 +128,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { res.setName( "Bruce" ); item.setDistributors( new HashSet() ); item.getDistributors().add( res ); - Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics(); + Statistics stats = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics(); stats.clear(); stats.setStatisticsEnabled( true ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/JpaTckUsageTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/JpaTckUsageTest.java index 840568b019..c7b582ffb3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/JpaTckUsageTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/JpaTckUsageTest.java @@ -12,20 +12,13 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.Collections; import java.util.List; -import java.util.Map; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.DerbyDialect; -import org.hibernate.dialect.DerbyTenSevenDialect; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.jpa.HibernateEntityManagerFactory; -import org.hibernate.orm.test.annotations.cid.C; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; -import org.hibernate.orm.test.jpa.procedure.User; import org.hibernate.testing.FailureExpected; import org.hibernate.testing.RequiresDialect; @@ -273,9 +266,8 @@ public class JpaTckUsageTest extends BaseEntityManagerFunctionalTestCase { } - private void createProcedures(HibernateEntityManagerFactory emf) { - final SessionFactoryImplementor sf = emf.unwrap( SessionFactoryImplementor.class ); - final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); + private void createProcedures(SessionFactoryImplementor emf) { + final JdbcConnectionAccess connectionAccess = emf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); final Connection conn; try { conn = connectionAccess.obtainConnection(); @@ -371,7 +363,7 @@ public class JpaTckUsageTest extends BaseEntityManagerFunctionalTestCase { conn.close(); } - private void createTestUser(HibernateEntityManagerFactory entityManagerFactory) { + private void createTestUser(SessionFactoryImplementor entityManagerFactory) { EntityManager em = entityManagerFactory.createEntityManager(); em.getTransaction().begin(); @@ -380,7 +372,7 @@ public class JpaTckUsageTest extends BaseEntityManagerFunctionalTestCase { em.close(); } - private void deleteTestUser(HibernateEntityManagerFactory entityManagerFactory) { + private void deleteTestUser(SessionFactoryImplementor entityManagerFactory) { EntityManager em = entityManagerFactory.createEntityManager(); em.getTransaction().begin(); em.createQuery( "delete from User" ).executeUpdate(); @@ -388,7 +380,7 @@ public class JpaTckUsageTest extends BaseEntityManagerFunctionalTestCase { em.close(); } - private void dropProcedures(HibernateEntityManagerFactory emf) { + private void dropProcedures(SessionFactoryImplementor emf) { final SessionFactoryImplementor sf = emf.unwrap( SessionFactoryImplementor.class ); final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); final Connection conn; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/FlushAndTransactionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/FlushAndTransactionTest.java index 1df35e9f5f..574c2fdfb7 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/FlushAndTransactionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/FlushAndTransactionTest.java @@ -8,6 +8,15 @@ package org.hibernate.orm.test.jpa.transaction; import java.util.List; import java.util.Map; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; +import org.hibernate.stat.Statistics; + +import org.junit.Test; + import jakarta.persistence.EntityManager; import jakarta.persistence.LockModeType; import jakarta.persistence.OptimisticLockException; @@ -16,14 +25,6 @@ import jakarta.persistence.Query; import jakarta.persistence.RollbackException; import jakarta.persistence.TransactionRequiredException; -import org.hibernate.Session; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.jpa.HibernateEntityManagerFactory; -import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; -import org.hibernate.stat.Statistics; - -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -66,7 +67,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase Book book = new Book(); book.name = "Le petit prince"; EntityManager em = getOrCreateEntityManager(); - Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics(); + Statistics stats = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics(); stats.clear(); stats.setStatisticsEnabled( true ); @@ -110,7 +111,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase Book book = new Book(); book.name = "Le petit prince"; EntityManager em = getOrCreateEntityManager(); - Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics(); + Statistics stats = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics(); em.getTransaction().begin(); em.persist( book ); diff --git a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/performance/AbstractEntityManagerTest.java b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/performance/AbstractEntityManagerTest.java index a4edf71e2f..b6e5f03c17 100644 --- a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/performance/AbstractEntityManagerTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/performance/AbstractEntityManagerTest.java @@ -9,21 +9,20 @@ package org.hibernate.orm.test.envers.performance; import java.io.IOException; import java.util.Arrays; import java.util.Properties; -import jakarta.persistence.EntityManager; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; -import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.boot.internal.EnversIntegrator; -import org.hibernate.orm.test.envers.AbstractEnversTest; -import org.hibernate.jpa.HibernateEntityManagerFactory; +import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; import org.hibernate.jpa.boot.spi.Bootstrap; +import org.hibernate.orm.test.envers.AbstractEnversTest; import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.BeforeClassOnce; @@ -31,6 +30,8 @@ import org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter; import org.hibernate.testing.orm.junit.DialectContext; import org.junit.Before; +import jakarta.persistence.EntityManager; + /** * @author Adam Warski (adam at warski dot org) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) @@ -40,7 +41,7 @@ public abstract class AbstractEntityManagerTest extends AbstractEnversTest { private EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder; private StandardServiceRegistryImpl serviceRegistry; - private HibernateEntityManagerFactory emf; + private SessionFactoryImplementor emf; private EntityManager entityManager; private AuditReader auditReader; private boolean audited; @@ -100,7 +101,7 @@ public abstract class AbstractEntityManagerTest extends AbstractEnversTest { configurationProperties ); - emf = entityManagerFactoryBuilder.build().unwrap( HibernateEntityManagerFactory.class ); + emf = entityManagerFactoryBuilder.build().unwrap( SessionFactoryImplementor.class ); serviceRegistry = (StandardServiceRegistryImpl) emf.getSessionFactory() .getServiceRegistry() diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java b/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java index 69baba0685..cf0e7eb142 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java @@ -35,6 +35,7 @@ import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.service.ServiceRegistry; import org.junit.Assert; @@ -585,7 +586,7 @@ public class TransactionUtil { * @param session Hibernate Session */ public static void setJdbcTimeout(Session session, long millis) { - final Dialect dialect = session.getSessionFactory().getSessionFactory().getJdbcServices().getDialect(); + final Dialect dialect = session.getSessionFactory().unwrap( SessionFactoryImplementor.class ).getJdbcServices().getDialect(); session.doWork( connection -> { if ( dialect instanceof PostgreSQLDialect ) { try (Statement st = connection.createStatement()) {