api, spi, internal, deprecation
This commit is contained in:
parent
ff79e0f12a
commit
6cbfb30ea4
|
@ -8,20 +8,21 @@ package org.hibernate;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import javax.naming.Referenceable;
|
import javax.naming.Referenceable;
|
||||||
import jakarta.persistence.EntityManagerFactory;
|
|
||||||
|
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
import org.hibernate.engine.spi.FilterDefinition;
|
import org.hibernate.engine.spi.FilterDefinition;
|
||||||
import org.hibernate.jpa.HibernateEntityManagerFactory;
|
|
||||||
import org.hibernate.metadata.ClassMetadata;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
import org.hibernate.metadata.CollectionMetadata;
|
import org.hibernate.metadata.CollectionMetadata;
|
||||||
import org.hibernate.stat.Statistics;
|
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
|
* The main contract here is the creation of {@link Session} instances. Usually
|
||||||
* an application has a single {@link SessionFactory} instance and threads
|
* an application has a single {@link SessionFactory} instance and threads
|
||||||
|
@ -38,7 +39,7 @@ import org.hibernate.stat.Statistics;
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
* @author Steve Ebersole
|
* @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.
|
* Get the special options used to build the factory.
|
||||||
*
|
*
|
||||||
|
@ -240,6 +241,13 @@ public interface SessionFactory extends EntityManagerFactory, HibernateEntityMan
|
||||||
@Override
|
@Override
|
||||||
Cache getCache();
|
Cache getCache();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all EntityGraphs registered for a particular entity type
|
||||||
|
*
|
||||||
|
* @see #addNamedEntityGraph
|
||||||
|
*/
|
||||||
|
<T> List<EntityGraph<? super T>> findEntityGraphsByType(Class<T> entityClass);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain a set of the names of all filters defined on this SessionFactory.
|
* Obtain a set of the names of all filters defined on this SessionFactory.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -41,6 +41,15 @@ import java.io.Serializable;
|
||||||
* to the object, except when identity column key generation is used.
|
* to the object, except when identity column key generation is used.
|
||||||
*
|
*
|
||||||
* @see CallbackException
|
* @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
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
public interface Lifecycle {
|
public interface Lifecycle {
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.ejb;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link org.hibernate.jpa.HibernateEntityManager} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface HibernateEntityManager {
|
|
||||||
}
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.ejb;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link org.hibernate.jpa.HibernateEntityManagerFactory} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface HibernateEntityManagerFactory extends org.hibernate.jpa.HibernateEntityManagerFactory {
|
|
||||||
}
|
|
|
@ -251,8 +251,7 @@ public interface SessionFactoryImplementor
|
||||||
@Override
|
@Override
|
||||||
MetamodelImplementor getMetamodel();
|
MetamodelImplementor getMetamodel();
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
default <T> List<EntityGraph<? super T>> findEntityGraphsByType(Class<T> entityClass) {
|
default <T> List<EntityGraph<? super T>> findEntityGraphsByType(Class<T> entityClass) {
|
||||||
return (List) findEntityGraphsByJavaType( entityClass );
|
return (List) findEntityGraphsByJavaType( entityClass );
|
||||||
}
|
}
|
||||||
|
|
|
@ -2213,9 +2213,6 @@ public class SessionImpl
|
||||||
return getHibernateFlushMode() != FlushMode.MANUAL;
|
return getHibernateFlushMode() != FlushMode.MANUAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
// HibernateEntityManager impl
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SessionImplementor getSession() {
|
public SessionImplementor getSession() {
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
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();
|
|
||||||
}
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
<T> List<EntityGraph<? super T>> findEntityGraphsByType(Class<T> 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 <i>hibernate.ejb.entitymanager_factory_name</i>.
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,17 +10,13 @@ import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Properties;
|
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.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||||
import org.hibernate.event.spi.EventType;
|
import org.hibernate.event.spi.EventType;
|
||||||
import org.hibernate.internal.util.ConfigHelper;
|
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.Distributor;
|
||||||
import org.hibernate.orm.test.jpa.Item;
|
import org.hibernate.orm.test.jpa.Item;
|
||||||
import org.hibernate.orm.test.jpa.pack.cfgxmlpar.Morito;
|
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.AfterEach;
|
||||||
import org.junit.jupiter.api.Test;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
@ -373,7 +374,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase {
|
||||||
res.setName( "Bruce" );
|
res.setName( "Bruce" );
|
||||||
item.setDistributors( new HashSet<Distributor>() );
|
item.setDistributors( new HashSet<Distributor>() );
|
||||||
item.getDistributors().add( res );
|
item.getDistributors().add( res );
|
||||||
Statistics stats = ( (HibernateEntityManagerFactory) emf ).getSessionFactory().getStatistics();
|
Statistics stats = emf.unwrap( SessionFactory.class ).getStatistics();
|
||||||
stats.clear();
|
stats.clear();
|
||||||
stats.setStatisticsEnabled( true );
|
stats.setStatisticsEnabled( true );
|
||||||
|
|
||||||
|
|
|
@ -9,20 +9,18 @@
|
||||||
|
|
||||||
package org.hibernate.orm.test.jpa;
|
package org.hibernate.orm.test.jpa;
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.PersistenceException;
|
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.SessionFactoryImpl;
|
import org.hibernate.internal.SessionFactoryImpl;
|
||||||
import org.hibernate.jpa.HibernateEntityManagerFactory;
|
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
import org.hibernate.testing.orm.junit.Jpa;
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
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.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
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" );
|
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
|
@Test
|
||||||
public void testEntityManagerCanBeUnwrappedToObject(EntityManagerFactoryScope scope) {
|
public void testEntityManagerCanBeUnwrappedToObject(EntityManagerFactoryScope scope) {
|
||||||
Object object = scope.getEntityManagerFactory().unwrap( Object.class );
|
Object object = scope.getEntityManagerFactory().unwrap( Object.class );
|
||||||
|
|
|
@ -14,6 +14,19 @@ import java.io.ObjectOutputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
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.EntityExistsException;
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
|
@ -21,17 +34,6 @@ import jakarta.persistence.FlushModeType;
|
||||||
import jakarta.persistence.PersistenceException;
|
import jakarta.persistence.PersistenceException;
|
||||||
import jakarta.persistence.Query;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -126,7 +128,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
res.setName( "Bruce" );
|
res.setName( "Bruce" );
|
||||||
item.setDistributors( new HashSet<Distributor>() );
|
item.setDistributors( new HashSet<Distributor>() );
|
||||||
item.getDistributors().add( res );
|
item.getDistributors().add( res );
|
||||||
Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics();
|
Statistics stats = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
||||||
stats.clear();
|
stats.clear();
|
||||||
stats.setStatisticsEnabled( true );
|
stats.setStatisticsEnabled( true );
|
||||||
|
|
||||||
|
|
|
@ -12,20 +12,13 @@ import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
|
||||||
import org.hibernate.dialect.DerbyDialect;
|
import org.hibernate.dialect.DerbyDialect;
|
||||||
import org.hibernate.dialect.DerbyTenSevenDialect;
|
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
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.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.orm.test.jpa.procedure.User;
|
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
|
@ -273,9 +266,8 @@ public class JpaTckUsageTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createProcedures(HibernateEntityManagerFactory emf) {
|
private void createProcedures(SessionFactoryImplementor emf) {
|
||||||
final SessionFactoryImplementor sf = emf.unwrap( SessionFactoryImplementor.class );
|
final JdbcConnectionAccess connectionAccess = emf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess();
|
||||||
final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess();
|
|
||||||
final Connection conn;
|
final Connection conn;
|
||||||
try {
|
try {
|
||||||
conn = connectionAccess.obtainConnection();
|
conn = connectionAccess.obtainConnection();
|
||||||
|
@ -371,7 +363,7 @@ public class JpaTckUsageTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTestUser(HibernateEntityManagerFactory entityManagerFactory) {
|
private void createTestUser(SessionFactoryImplementor entityManagerFactory) {
|
||||||
EntityManager em = entityManagerFactory.createEntityManager();
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
@ -380,7 +372,7 @@ public class JpaTckUsageTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteTestUser(HibernateEntityManagerFactory entityManagerFactory) {
|
private void deleteTestUser(SessionFactoryImplementor entityManagerFactory) {
|
||||||
EntityManager em = entityManagerFactory.createEntityManager();
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.createQuery( "delete from User" ).executeUpdate();
|
em.createQuery( "delete from User" ).executeUpdate();
|
||||||
|
@ -388,7 +380,7 @@ public class JpaTckUsageTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dropProcedures(HibernateEntityManagerFactory emf) {
|
private void dropProcedures(SessionFactoryImplementor emf) {
|
||||||
final SessionFactoryImplementor sf = emf.unwrap( SessionFactoryImplementor.class );
|
final SessionFactoryImplementor sf = emf.unwrap( SessionFactoryImplementor.class );
|
||||||
final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess();
|
final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess();
|
||||||
final Connection conn;
|
final Connection conn;
|
||||||
|
|
|
@ -8,6 +8,15 @@ package org.hibernate.orm.test.jpa.transaction;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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.EntityManager;
|
||||||
import jakarta.persistence.LockModeType;
|
import jakarta.persistence.LockModeType;
|
||||||
import jakarta.persistence.OptimisticLockException;
|
import jakarta.persistence.OptimisticLockException;
|
||||||
|
@ -16,14 +25,6 @@ import jakarta.persistence.Query;
|
||||||
import jakarta.persistence.RollbackException;
|
import jakarta.persistence.RollbackException;
|
||||||
import jakarta.persistence.TransactionRequiredException;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -66,7 +67,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.name = "Le petit prince";
|
book.name = "Le petit prince";
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics();
|
Statistics stats = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
||||||
stats.clear();
|
stats.clear();
|
||||||
stats.setStatisticsEnabled( true );
|
stats.setStatisticsEnabled( true );
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.name = "Le petit prince";
|
book.name = "Le petit prince";
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics();
|
Statistics stats = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
||||||
|
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist( book );
|
em.persist( book );
|
||||||
|
|
|
@ -9,21 +9,20 @@ package org.hibernate.orm.test.envers.performance;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
|
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
import org.hibernate.envers.AuditReaderFactory;
|
import org.hibernate.envers.AuditReaderFactory;
|
||||||
import org.hibernate.envers.configuration.EnversSettings;
|
|
||||||
import org.hibernate.envers.boot.internal.EnversIntegrator;
|
import org.hibernate.envers.boot.internal.EnversIntegrator;
|
||||||
import org.hibernate.orm.test.envers.AbstractEnversTest;
|
import org.hibernate.envers.configuration.EnversSettings;
|
||||||
import org.hibernate.jpa.HibernateEntityManagerFactory;
|
|
||||||
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
|
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
|
||||||
import org.hibernate.jpa.boot.spi.Bootstrap;
|
import org.hibernate.jpa.boot.spi.Bootstrap;
|
||||||
|
import org.hibernate.orm.test.envers.AbstractEnversTest;
|
||||||
|
|
||||||
import org.hibernate.testing.AfterClassOnce;
|
import org.hibernate.testing.AfterClassOnce;
|
||||||
import org.hibernate.testing.BeforeClassOnce;
|
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.hibernate.testing.orm.junit.DialectContext;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||||
|
@ -40,7 +41,7 @@ public abstract class AbstractEntityManagerTest extends AbstractEnversTest {
|
||||||
|
|
||||||
private EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder;
|
private EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder;
|
||||||
private StandardServiceRegistryImpl serviceRegistry;
|
private StandardServiceRegistryImpl serviceRegistry;
|
||||||
private HibernateEntityManagerFactory emf;
|
private SessionFactoryImplementor emf;
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
private AuditReader auditReader;
|
private AuditReader auditReader;
|
||||||
private boolean audited;
|
private boolean audited;
|
||||||
|
@ -100,7 +101,7 @@ public abstract class AbstractEntityManagerTest extends AbstractEnversTest {
|
||||||
configurationProperties
|
configurationProperties
|
||||||
);
|
);
|
||||||
|
|
||||||
emf = entityManagerFactoryBuilder.build().unwrap( HibernateEntityManagerFactory.class );
|
emf = entityManagerFactoryBuilder.build().unwrap( SessionFactoryImplementor.class );
|
||||||
|
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) emf.getSessionFactory()
|
serviceRegistry = (StandardServiceRegistryImpl) emf.getSessionFactory()
|
||||||
.getServiceRegistry()
|
.getServiceRegistry()
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.hibernate.dialect.SQLServerDialect;
|
||||||
import org.hibernate.dialect.SybaseASEDialect;
|
import org.hibernate.dialect.SybaseASEDialect;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -585,7 +586,7 @@ public class TransactionUtil {
|
||||||
* @param session Hibernate Session
|
* @param session Hibernate Session
|
||||||
*/
|
*/
|
||||||
public static void setJdbcTimeout(Session session, long millis) {
|
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 -> {
|
session.doWork( connection -> {
|
||||||
if ( dialect instanceof PostgreSQLDialect ) {
|
if ( dialect instanceof PostgreSQLDialect ) {
|
||||||
try (Statement st = connection.createStatement()) {
|
try (Statement st = connection.createStatement()) {
|
||||||
|
|
Loading…
Reference in New Issue