Package org.hibernate.internal
Class SessionFactoryImpl
- java.lang.Object
-
- org.hibernate.internal.QueryParameterBindingTypeResolverImpl
-
- org.hibernate.internal.SessionFactoryImpl
-
- All Implemented Interfaces:
EntityManagerFactory
,Closeable
,Serializable
,AutoCloseable
,Referenceable
,Mapping
,SessionFactoryImplementor
,QueryParameterBindingTypeResolver
,SqmCreationContext
,SessionFactory
,SqlAstCreationContext
public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl implements SessionFactoryImplementor
Concrete implementation of theSessionFactory
API.Exposes two interfaces:
SessionFactory
to the application, andSessionImplementor
(an SPI interface) to other subsystems.
This class is thread-safe.
- See Also:
- Serialized Form
- Implementation Note:
- This class must appear immutable to clients, even if it does all kinds of caching and pooling under the covers. It is crucial that the class is not only thread-safe, but also highly concurrent. Synchronization must be used extremely sparingly.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SessionFactoryImpl.SessionBuilderImpl
static class
SessionFactoryImpl.StatelessSessionBuilderImpl
-
Nested classes/interfaces inherited from interface org.hibernate.engine.spi.SessionFactoryImplementor
SessionFactoryImplementor.DeserializationResolver<T extends SessionFactoryImplementor>
-
-
Constructor Summary
Constructors Constructor Description SessionFactoryImpl(MetadataImplementor bootMetamodel, SessionFactoryOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.This constructor will be removedSessionFactoryImpl(MetadataImplementor bootMetamodel, SessionFactoryOptions options, BootstrapContext bootstrapContext)
-
Method Summary
-
Methods inherited from class org.hibernate.internal.QueryParameterBindingTypeResolverImpl
resolveParameterBindType, resolveParameterBindType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hibernate.query.spi.QueryParameterBindingTypeResolver
getMappingMetamodel
-
Methods inherited from interface org.hibernate.SessionFactory
fromSession, fromStatelessSession, fromStatelessTransaction, fromTransaction, inSession, inStatelessSession, inStatelessTransaction, inTransaction
-
Methods inherited from interface org.hibernate.engine.spi.SessionFactoryImplementor
getMappingMetamodel, getSessionFactory, resolveParameterBindType, resolveParameterBindType
-
Methods inherited from interface org.hibernate.query.sqm.spi.SqmCreationContext
getNodeBuilder
-
-
-
-
Constructor Detail
-
SessionFactoryImpl
@Deprecated(since="6.2", forRemoval=true) public SessionFactoryImpl(MetadataImplementor bootMetamodel, SessionFactoryOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.This constructor will be removed
-
SessionFactoryImpl
public SessionFactoryImpl(MetadataImplementor bootMetamodel, SessionFactoryOptions options, BootstrapContext bootstrapContext)
-
-
Method Detail
-
openSession
public SessionImplementor openSession() throws HibernateException
Description copied from interface:SessionFactoryImplementor
OverridesSessionFactory.openSession()
to widen the return type: this is useful for internal code depending onSessionFactoryImplementor
as it would otherwise need to frequently resort to casting to the internal contract.- Specified by:
openSession
in interfaceSessionFactory
- Specified by:
openSession
in interfaceSessionFactoryImplementor
- Returns:
- the opened Session.
- Throws:
HibernateException
- Indicates a problem opening the session; pretty rare here.
-
openTemporarySession
public SessionImpl openTemporarySession() throws HibernateException
Description copied from interface:SessionFactoryImplementor
Get a non-transactional "current" session (used by hibernate-envers)- Specified by:
openTemporarySession
in interfaceSessionFactoryImplementor
- Throws:
HibernateException
-
getCurrentSession
public Session getCurrentSession() throws HibernateException
Description copied from interface:SessionFactory
Obtains the current session, an instance ofSession
implicitly associated with some context or scope. For example, the session might be associated with the current thread, or with the current JTA transaction.The context used for scoping the current session (that is, the definition of what precisely "current" means here) is determined by an implementation of
CurrentSessionContext
. An implementation may be selected using the configuration property "hibernate.current_session_context_class".If no
CurrentSessionContext
is explicitly configured, but JTA support is enabled, thenJTASessionContext
is used, and the current session is scoped to the active JTA transaction.- Specified by:
getCurrentSession
in interfaceSessionFactory
- Returns:
- The current session.
- Throws:
HibernateException
- Indicates an issue locating a suitable current session.- See Also:
CurrentSessionContext
,AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS
-
withOptions
public SessionFactoryImpl.SessionBuilderImpl withOptions()
Description copied from interface:SessionFactory
Obtain a session builder for creating newSession
s with certain customized options.- Specified by:
withOptions
in interfaceSessionFactory
- Specified by:
withOptions
in interfaceSessionFactoryImplementor
- Returns:
- The session builder
-
withStatelessOptions
public StatelessSessionBuilder withStatelessOptions()
Description copied from interface:SessionFactory
Obtain aStatelessSession
builder.- Specified by:
withStatelessOptions
in interfaceSessionFactory
- Returns:
- The stateless session builder
-
openStatelessSession
public StatelessSession openStatelessSession()
Description copied from interface:SessionFactory
Open a new stateless session.- Specified by:
openStatelessSession
in interfaceSessionFactory
- Returns:
- The created stateless session.
-
openStatelessSession
public StatelessSession openStatelessSession(Connection connection)
Description copied from interface:SessionFactory
Open a new stateless session, utilizing the specified JDBCConnection
.- Specified by:
openStatelessSession
in interfaceSessionFactory
- Parameters:
connection
- Connection provided by the application.- Returns:
- The created stateless session.
-
addObserver
public void addObserver(SessionFactoryObserver observer)
- Specified by:
addObserver
in interfaceSessionFactoryImplementor
-
getProperties
public Map<String,Object> getProperties()
- Specified by:
getProperties
in interfaceEntityManagerFactory
-
validateNotClosed
protected void validateNotClosed()
-
getUuid
public String getUuid()
Description copied from interface:SessionFactoryImplementor
Get the UUID for this SessionFactory.The value is generated as a
UUID
, but kept as a String.- Specified by:
getUuid
in interfaceSessionFactoryImplementor
- Returns:
- The UUID for this SessionFactory.
- See Also:
SessionFactoryRegistry.getSessionFactory(java.lang.String)
-
getName
public String getName()
Description copied from interface:SessionFactoryImplementor
Access to the name (if one) assigned to the SessionFactory- Specified by:
getName
in interfaceSessionFactoryImplementor
- Returns:
- The name for the SessionFactory
-
getTypeConfiguration
public TypeConfiguration getTypeConfiguration()
- Specified by:
getTypeConfiguration
in interfaceQueryParameterBindingTypeResolver
- Specified by:
getTypeConfiguration
in interfaceSessionFactoryImplementor
- Specified by:
getTypeConfiguration
in interfaceSqmCreationContext
-
getQueryEngine
public QueryEngine getQueryEngine()
- Specified by:
getQueryEngine
in interfaceSessionFactoryImplementor
- Specified by:
getQueryEngine
in interfaceSqmCreationContext
-
getEventEngine
public EventEngine getEventEngine()
Description copied from interface:SessionFactoryImplementor
Get the EventEngine associated with this SessionFactory- Specified by:
getEventEngine
in interfaceSessionFactoryImplementor
-
getJdbcServices
public JdbcServices getJdbcServices()
Description copied from interface:SessionFactoryImplementor
Get the JdbcServices.- Specified by:
getJdbcServices
in interfaceSessionFactoryImplementor
- Returns:
- the JdbcServices
-
getSqlStringGenerationContext
public SqlStringGenerationContext getSqlStringGenerationContext()
- Specified by:
getSqlStringGenerationContext
in interfaceSessionFactoryImplementor
-
getIdentifierGeneratorFactory
public IdentifierGeneratorFactory getIdentifierGeneratorFactory()
-
getDeserializationResolver
@Deprecated public SessionFactoryImplementor.DeserializationResolver<?> getDeserializationResolver()
Deprecated.- Specified by:
getDeserializationResolver
in interfaceSessionFactoryImplementor
-
findEntityGraphsByType
public <T> List<EntityGraph<? super T>> findEntityGraphsByType(Class<T> entityClass)
Description copied from interface:SessionFactory
Return allEntityGraph
s registered for the given entity type.- Specified by:
findEntityGraphsByType
in interfaceSessionFactory
- See Also:
EntityManagerFactory.addNamedEntityGraph(java.lang.String, jakarta.persistence.EntityGraph<T>)
-
createEntityManager
public Session createEntityManager()
- Specified by:
createEntityManager
in interfaceEntityManagerFactory
-
createEntityManager
public Session createEntityManager(Map map)
- Specified by:
createEntityManager
in interfaceEntityManagerFactory
-
createEntityManager
public Session createEntityManager(SynchronizationType synchronizationType)
- Specified by:
createEntityManager
in interfaceEntityManagerFactory
-
createEntityManager
public Session createEntityManager(SynchronizationType synchronizationType, Map map)
- Specified by:
createEntityManager
in interfaceEntityManagerFactory
-
getCriteriaBuilder
public NodeBuilder getCriteriaBuilder()
Description copied from interface:SessionFactory
- Specified by:
getCriteriaBuilder
in interfaceEntityManagerFactory
- Specified by:
getCriteriaBuilder
in interfaceSessionFactory
- Specified by:
getCriteriaBuilder
in interfaceSessionFactoryImplementor
- See Also:
SharedSessionContract.getCriteriaBuilder()
-
getMetamodel
public MetamodelImplementor getMetamodel()
- Specified by:
getMetamodel
in interfaceEntityManagerFactory
- Specified by:
getMetamodel
in interfaceSessionFactoryImplementor
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfaceEntityManagerFactory
-
findEntityGraphByName
public RootGraphImplementor<?> findEntityGraphByName(String name)
Description copied from interface:SessionFactory
Return the rootEntityGraph
with the given name, ornull
if there is no graph with the given name.- Specified by:
findEntityGraphByName
in interfaceSessionFactory
- Specified by:
findEntityGraphByName
in interfaceSessionFactoryImplementor
- Parameters:
name
- the name given to someNamedEntityGraph
- Returns:
- an instance of
RootGraph
- See Also:
EntityManagerFactory.addNamedEntityGraph(java.lang.String, jakarta.persistence.EntityGraph<T>)
-
bestGuessEntityName
public String bestGuessEntityName(Object object)
Description copied from interface:SessionFactoryImplementor
The best guess entity name for an entity not in an association- Specified by:
bestGuessEntityName
in interfaceSessionFactoryImplementor
-
getSessionFactoryOptions
public SessionFactoryOptions getSessionFactoryOptions()
Description copied from interface:SessionFactory
Get the options used to build this factory.- Specified by:
getSessionFactoryOptions
in interfaceSessionFactory
- Specified by:
getSessionFactoryOptions
in interfaceSessionFactoryImplementor
- Returns:
- The special options used to build the factory.
-
getInterceptor
public Interceptor getInterceptor()
-
getReference
public Reference getReference()
- Specified by:
getReference
in interfaceReferenceable
-
getIdentifierType
public Type getIdentifierType(String className) throws MappingException
- Specified by:
getIdentifierType
in interfaceMapping
- Throws:
MappingException
-
getIdentifierPropertyName
public String getIdentifierPropertyName(String className) throws MappingException
- Specified by:
getIdentifierPropertyName
in interfaceMapping
- Throws:
MappingException
-
getCollectionMetadata
public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException
- Throws:
HibernateException
-
getReferencedPropertyType
public Type getReferencedPropertyType(String className, String propertyName) throws MappingException
- Specified by:
getReferencedPropertyType
in interfaceMapping
- Throws:
MappingException
-
close
public void close() throws HibernateException
Closes the session factory, releasing all held resources.- cleans up used cache regions and "stops" the cache provider.
- close the JDBC connection
- remove the JNDI binding
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceEntityManagerFactory
- Specified by:
close
in interfaceSessionFactory
- Throws:
HibernateException
- Indicates an issue closing the factory.
-
getCache
public CacheImplementor getCache()
Description copied from interface:SessionFactory
Obtain direct access to the underlying cache regions.- Specified by:
getCache
in interfaceEntityManagerFactory
- Specified by:
getCache
in interfaceSessionFactory
- Specified by:
getCache
in interfaceSessionFactoryImplementor
- Returns:
- The direct cache access API.
-
getPersistenceUnitUtil
public PersistenceUnitUtil getPersistenceUnitUtil()
- Specified by:
getPersistenceUnitUtil
in interfaceEntityManagerFactory
-
addNamedQuery
public void addNamedQuery(String name, Query query)
- Specified by:
addNamedQuery
in interfaceEntityManagerFactory
-
unwrap
public <T> T unwrap(Class<T> type)
- Specified by:
unwrap
in interfaceEntityManagerFactory
-
addNamedEntityGraph
public <T> void addNamedEntityGraph(String graphName, EntityGraph<T> entityGraph)
- Specified by:
addNamedEntityGraph
in interfaceEntityManagerFactory
-
isClosed
public boolean isClosed()
Description copied from interface:SessionFactory
Is this factory already closed?- Specified by:
isClosed
in interfaceSessionFactory
- Returns:
- True if this factory is already closed; false otherwise.
-
getStatistics
public StatisticsImplementor getStatistics()
Description copied from interface:SessionFactory
Retrieve the statistics for this factory.- Specified by:
getStatistics
in interfaceSessionFactory
- Specified by:
getStatistics
in interfaceSessionFactoryImplementor
- Returns:
- The statistics.
-
getFilterDefinition
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException
Description copied from interface:SessionFactory
Obtain the definition of a filter by name.- Specified by:
getFilterDefinition
in interfaceSessionFactory
- Specified by:
getFilterDefinition
in interfaceSessionFactoryImplementor
- Parameters:
filterName
- The name of the filter for which to obtain the definition.- Returns:
- The filter definition.
- Throws:
HibernateException
- If no filter defined with the given name.
-
getAutoEnabledFilters
public Collection<FilterDefinition> getAutoEnabledFilters()
- Specified by:
getAutoEnabledFilters
in interfaceSessionFactoryImplementor
-
containsFetchProfileDefinition
public boolean containsFetchProfileDefinition(String name)
Description copied from interface:SessionFactory
Determine if there is a fetch profile definition registered under the given name.- Specified by:
containsFetchProfileDefinition
in interfaceSessionFactory
- Parameters:
name
- The name to check- Returns:
- True if there is such a fetch profile; false otherwise.
-
getDefinedFilterNames
public Set<String> getDefinedFilterNames()
Description copied from interface:SessionFactory
Obtain the set of names of alldefined filters
.- Specified by:
getDefinedFilterNames
in interfaceSessionFactory
- Returns:
- The set of filter names given by
FilterDef
annotations
-
getDefinedFetchProfileNames
public Set<String> getDefinedFetchProfileNames()
Description copied from interface:SessionFactory
Obtain the set of names of alldefined fetch profiles
.- Specified by:
getDefinedFetchProfileNames
in interfaceSessionFactory
- Returns:
- The set of fetch profile names given by
FetchProfile
annotations.
-
getIdentifierGenerator
@Deprecated public IdentifierGenerator getIdentifierGenerator(String rootEntityName)
Deprecated.Description copied from interface:SessionFactoryImplementor
Get the identifier generator for the hierarchy- Specified by:
getIdentifierGenerator
in interfaceSessionFactoryImplementor
-
getGenerator
@Deprecated public Generator getGenerator(String rootEntityName)
Deprecated.Description copied from interface:SessionFactoryImplementor
Get the identifier generator for the hierarchy- Specified by:
getGenerator
in interfaceSessionFactoryImplementor
-
getRuntimeMetamodels
public RuntimeMetamodelsImplementor getRuntimeMetamodels()
- Specified by:
getRuntimeMetamodels
in interfaceSessionFactoryImplementor
-
getJpaMetamodel
public JpaMetamodelImplementor getJpaMetamodel()
Description copied from interface:SqmCreationContext
Access to the domain model metadata- Specified by:
getJpaMetamodel
in interfaceSqmCreationContext
-
getMaximumFetchDepth
public Integer getMaximumFetchDepth()
Description copied from interface:SqlAstCreationContext
When creatingFetch
references, defines a limit to how deep we should join for fetches.- Specified by:
getMaximumFetchDepth
in interfaceSqlAstCreationContext
-
getServiceRegistry
public ServiceRegistryImplementor getServiceRegistry()
Description copied from interface:SessionFactoryImplementor
Access to the ServiceRegistry for this SessionFactory.- Specified by:
getServiceRegistry
in interfaceSessionFactoryImplementor
- Specified by:
getServiceRegistry
in interfaceSqlAstCreationContext
- Specified by:
getServiceRegistry
in interfaceSqmCreationContext
- Returns:
- The factory's ServiceRegistry
-
getEntityNotFoundDelegate
public EntityNotFoundDelegate getEntityNotFoundDelegate()
- Specified by:
getEntityNotFoundDelegate
in interfaceSessionFactoryImplementor
-
getFetchProfile
public FetchProfile getFetchProfile(String name)
Description copied from interface:SessionFactoryImplementor
Retrieve fetch profile by name.- Specified by:
getFetchProfile
in interfaceSessionFactoryImplementor
- Parameters:
name
- The name of the profile to retrieve.- Returns:
- The profile definition
-
configuredInterceptor
@Deprecated public static Interceptor configuredInterceptor(Interceptor interceptor, SessionFactoryOptions options)
-
configuredInterceptor
public static Interceptor configuredInterceptor(Interceptor interceptor, boolean explicitNoInterceptor, SessionFactoryOptions options)
-
getCustomEntityDirtinessStrategy
public CustomEntityDirtinessStrategy getCustomEntityDirtinessStrategy()
- Specified by:
getCustomEntityDirtinessStrategy
in interfaceSessionFactoryImplementor
-
getCurrentTenantIdentifierResolver
public CurrentTenantIdentifierResolver<Object> getCurrentTenantIdentifierResolver()
- Specified by:
getCurrentTenantIdentifierResolver
in interfaceSessionFactoryImplementor
-
getTenantIdentifierJavaType
public JavaType<Object> getTenantIdentifierJavaType()
Description copied from interface:SessionFactoryImplementor
The java type to use for a tenant identifier.- Specified by:
getTenantIdentifierJavaType
in interfaceSessionFactoryImplementor
-
getFastSessionServices
public FastSessionServices getFastSessionServices()
- Specified by:
getFastSessionServices
in interfaceSessionFactoryImplementor
- Returns:
- the
FastSessionServices
for thisSessionFactory
.
-
getWrapperOptions
public WrapperOptions getWrapperOptions()
- Specified by:
getWrapperOptions
in interfaceSessionFactoryImplementor
-
getSchemaManager
public SchemaManager getSchemaManager()
Description copied from interface:SessionFactory
ASchemaManager
with the same default catalog and schema as pooled connections belonging to this factory. Intended mostly as a convenience for writing tests.- Specified by:
getSchemaManager
in interfaceSessionFactory
-
-