Class SessionFactoryImpl
- All Implemented Interfaces:
EntityManagerFactory
,Serializable
,AutoCloseable
,Referenceable
,SessionFactoryImplementor
,SessionFactory
SessionFactory
API.
Exposes two interfaces:
SessionFactory
to the application, andSessionImplementor
(an SPI interface) to other subsystems.
This class is thread-safe.
- See Also:
- 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 ClassesModifier and TypeClassDescriptionstatic class
static class
-
Constructor Summary
ConstructorsConstructorDescriptionSessionFactoryImpl
(MetadataImplementor bootMetamodel, SessionFactoryOptions options, BootstrapContext bootstrapContext) -
Method Summary
Modifier and TypeMethodDescription<T> void
addNamedEntityGraph
(String graphName, EntityGraph<T> entityGraph) void
addNamedQuery
(String name, Query query) void
addObserver
(SessionFactoryObserver observer) Register aSessionFactoryObserver
of this factory.bestGuessEntityName
(Object object) The best guess entity name for an entity not in an association<R> R
callInTransaction
(Function<EntityManager, R> work) void
close()
Closes the session factory, releasing all held resources.static Interceptor
configuredInterceptor
(Interceptor interceptor, boolean explicitNoInterceptor, SessionFactoryOptions options) static Interceptor
configuredInterceptor
(Interceptor interceptor, SessionFactoryOptions options) Deprecated.boolean
Determine if there is a fetch profile definition registered under the given name.Create a newSession
.createEntityManager
(SynchronizationType synchronizationType) Create a newSession
, with the given synchronization type.createEntityManager
(SynchronizationType synchronizationType, Map map) createEntityManager
(Map map) Create a newSession
, with the given properties.createGraphForDynamicEntity
(String entityName) Create anEntityGraph
which may be used from loading a dynamic entity withEntityManager.find(EntityGraph, Object, FindOption...)
.findEntityGraphByName
(String name) Return the rootEntityGraph
with the given name, ornull
if there is no graph with the given name.<T> List<EntityGraph<? super T>>
findEntityGraphsByType
(Class<T> entityClass) Return allEntityGraph
s registered for the given entity type.Obtain a collection ofFilterDefinition
s representing all the auto-enabled filters.getCache()
Obtain theCacheImplementor
.Obtain theClassLoaderService
.Obtains the current session, an instance ofSession
implicitly associated with some context or scope.Obtain theCurrentTenantIdentifierResolver
Obtain theCustomEntityDirtinessStrategy
Obtain the set of names of alldefined fetch profiles
.Obtain the set of names of alldefined filters
.Obtain theEntityCopyObserverFactory
service.Obtain theEntityNotFoundDelegate
Get the EventEngine associated with this SessionFactoryAccess to the event listener groups.Obtain theEventListenerRegistry
service.getFetchProfile
(String name) Retrieve a fetch profile by name.getFilterDefinition
(String filterName) Obtain the definition of a filter by name.getGenerator
(String rootEntityName) Deprecated.Obtain theJdbcServices
service.Obtain theJdbcServices
service.The JNDI name, used to bind theSessionFactory
to JNDI.Obtain theJpaMetamodel
Obtain theManagedBeanRegistry
service.Obtain theMappingMetamodelImplementor
getName()
The name assigned to thisSessionFactory
, if any.<E> Map<String,
EntityGraph<? extends E>> getNamedEntityGraphs
(Class<E> entityType) <R> Map<String,
TypedQueryReference<R>> getNamedQueries
(Class<R> resultType) Obtain theParameterMarkerStrategy
service.Obtain theQueryEngine
Obtain theRuntimeMetamodelsImplementor
ASchemaManager
with the same default catalog and schema as pooled connections belonging to this factory.Access to theServiceRegistry
for thisSessionFactory
.Get the options used to build this factory.Obtain theSqlStringGenerationContext
.Obtain theSqlTranslationEngine
Obtain theStatisticsImplementor
.TheJavaType
to use for a tenant identifier.Obtain theTypeConfiguration
getUuid()
The UUID assigned to thisSessionFactory
.Return an instance ofWrapperOptions
which is not backed by a session, and whose functionality is therefore incomplete.boolean
isClosed()
Is this factory already closed?boolean
isOpen()
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.Open a new stateless session.openStatelessSession
(Connection connection) Open a new stateless session, utilizing the specified JDBCConnection
.Get a non-transactional "current" session.void
<T> T
protected void
Obtain a session builder for creating new instances ofSession
with certain customized options.Obtain aStatelessSession
builder.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.hibernate.SessionFactory
fromSession, fromStatelessSession, fromStatelessTransaction, fromTransaction, inSession, inStatelessSession, inStatelessTransaction, inTransaction
-
Constructor Details
-
SessionFactoryImpl
public SessionFactoryImpl(MetadataImplementor bootMetamodel, SessionFactoryOptions options, BootstrapContext bootstrapContext)
-
-
Method Details
-
getEventListenerGroups
Description copied from interface:SessionFactoryImplementor
Access to the event listener groups.- Specified by:
getEventListenerGroups
in interfaceSessionFactoryImplementor
-
getParameterMarkerStrategy
Description copied from interface:SessionFactoryImplementor
Obtain theParameterMarkerStrategy
service.- Specified by:
getParameterMarkerStrategy
in interfaceSessionFactoryImplementor
-
getJdbcValuesMappingProducerProvider
Description copied from interface:SessionFactoryImplementor
Obtain theJdbcServices
service.- Specified by:
getJdbcValuesMappingProducerProvider
in interfaceSessionFactoryImplementor
-
getEntityCopyObserver
Description copied from interface:SessionFactoryImplementor
Obtain theEntityCopyObserverFactory
service.- Specified by:
getEntityCopyObserver
in interfaceSessionFactoryImplementor
-
getClassLoaderService
Description copied from interface:SessionFactoryImplementor
Obtain theClassLoaderService
.- Specified by:
getClassLoaderService
in interfaceSessionFactoryImplementor
-
getManagedBeanRegistry
Description copied from interface:SessionFactoryImplementor
Obtain theManagedBeanRegistry
service.- Specified by:
getManagedBeanRegistry
in interfaceSessionFactoryImplementor
-
getEventListenerRegistry
Description copied from interface:SessionFactoryImplementor
Obtain theEventListenerRegistry
service.- Specified by:
getEventListenerRegistry
in interfaceSessionFactoryImplementor
-
openSession
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
.
-
openTemporarySession
Description copied from interface:SessionFactoryImplementor
Get a non-transactional "current" session.- Specified by:
openTemporarySession
in interfaceSessionFactoryImplementor
-
getCurrentSession
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.
- See Also:
-
withOptions
Description copied from interface:SessionFactoryImplementor
Obtain a session builder for creating new instances ofSession
with certain customized options.- Specified by:
withOptions
in interfaceSessionFactory
- Specified by:
withOptions
in interfaceSessionFactoryImplementor
- Returns:
- The session builder
-
withStatelessOptions
Description copied from interface:SessionFactory
Obtain aStatelessSession
builder.- Specified by:
withStatelessOptions
in interfaceSessionFactory
- Returns:
- The stateless session builder
-
openStatelessSession
Description copied from interface:SessionFactory
Open a new stateless session.- Specified by:
openStatelessSession
in interfaceSessionFactory
- Returns:
- The new stateless session.
-
openStatelessSession
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 new stateless session.
-
addObserver
Description copied from interface:SessionFactoryImplementor
Register aSessionFactoryObserver
of this factory.- Specified by:
addObserver
in interfaceSessionFactoryImplementor
-
getProperties
- Specified by:
getProperties
in interfaceEntityManagerFactory
-
validateNotClosed
protected void validateNotClosed() -
getUuid
Description copied from interface:SessionFactoryImplementor
The UUID assigned to thisSessionFactory
.The value is generated as a
UUID
, but kept as a string.- Specified by:
getUuid
in interfaceSessionFactoryImplementor
- See Also:
-
getName
Description copied from interface:SessionFactory
The name assigned to thisSessionFactory
, if any.- When bootstrapping via JPA, this is the persistence unit name.
- Otherwise, the name may be specified by the configuration property "hibernate.session_factory_name".
If "hibernate.session_factory_name_is_jndi" is enabled, then this name is used to bind this object to JNDI, unless "hibernate.session_factory_jndi_name" is also specified.
- Specified by:
getName
in interfaceEntityManagerFactory
- Specified by:
getName
in interfaceSessionFactory
- See Also:
-
getJndiName
Description copied from interface:SessionFactory
The JNDI name, used to bind theSessionFactory
to JNDI.- Specified by:
getJndiName
in interfaceSessionFactory
-
getTypeConfiguration
Description copied from interface:SessionFactoryImplementor
Obtain theTypeConfiguration
- Specified by:
getTypeConfiguration
in interfaceSessionFactoryImplementor
-
getQueryEngine
Description copied from interface:SessionFactoryImplementor
Obtain theQueryEngine
- Specified by:
getQueryEngine
in interfaceSessionFactoryImplementor
-
getSqlTranslationEngine
Description copied from interface:SessionFactoryImplementor
Obtain theSqlTranslationEngine
- Specified by:
getSqlTranslationEngine
in interfaceSessionFactoryImplementor
-
getEventEngine
Description copied from interface:SessionFactoryImplementor
Get the EventEngine associated with this SessionFactory- Specified by:
getEventEngine
in interfaceSessionFactoryImplementor
-
getJdbcServices
Description copied from interface:SessionFactoryImplementor
Obtain theJdbcServices
service.- Specified by:
getJdbcServices
in interfaceSessionFactoryImplementor
-
getSqlStringGenerationContext
Description copied from interface:SessionFactoryImplementor
Obtain theSqlStringGenerationContext
.- Specified by:
getSqlStringGenerationContext
in interfaceSessionFactoryImplementor
-
findEntityGraphsByType
Description copied from interface:SessionFactory
Return allEntityGraph
s registered for the given entity type.- Specified by:
findEntityGraphsByType
in interfaceSessionFactory
- See Also:
-
createEntityManager
Description copied from interface:SessionFactory
Create a newSession
.- Specified by:
createEntityManager
in interfaceEntityManagerFactory
- Specified by:
createEntityManager
in interfaceSessionFactory
-
createEntityManager
Description copied from interface:SessionFactory
Create a newSession
, with the given properties.- Specified by:
createEntityManager
in interfaceEntityManagerFactory
- Specified by:
createEntityManager
in interfaceSessionFactory
-
createEntityManager
Description copied from interface:SessionFactory
Create a newSession
, with the given synchronization type.- Specified by:
createEntityManager
in interfaceEntityManagerFactory
- Specified by:
createEntityManager
in interfaceSessionFactory
-
createEntityManager
Description copied from interface:SessionFactory
- Specified by:
createEntityManager
in interfaceEntityManagerFactory
- Specified by:
createEntityManager
in interfaceSessionFactory
-
getCriteriaBuilder
Description copied from interface:SessionFactory
- Specified by:
getCriteriaBuilder
in interfaceEntityManagerFactory
- Specified by:
getCriteriaBuilder
in interfaceSessionFactory
- See Also:
-
getMetamodel
- Specified by:
getMetamodel
in interfaceEntityManagerFactory
-
isOpen
public boolean isOpen()- Specified by:
isOpen
in interfaceEntityManagerFactory
-
createGraphForDynamicEntity
Description copied from interface:SessionFactory
Create anEntityGraph
which may be used from loading a dynamic entity withEntityManager.find(EntityGraph, Object, FindOption...)
.This allows a dynamic entity to be loaded without the need for a cast.
var MyDynamicEntity_ = factory.createGraphForDynamicEntity("MyDynamicEntity"); Map<String,?> myDynamicEntity = session.find(MyDynamicEntity_, id);
- Specified by:
createGraphForDynamicEntity
in interfaceSessionFactory
- Parameters:
entityName
- The name of the dynamic entity- See Also:
-
findEntityGraphByName
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:
-
bestGuessEntityName
Description copied from interface:SessionFactoryImplementor
The best guess entity name for an entity not in an association- Specified by:
bestGuessEntityName
in interfaceSessionFactoryImplementor
-
getSessionFactoryOptions
Description copied from interface:SessionFactoryImplementor
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
-
getReference
- Specified by:
getReference
in interfaceReferenceable
-
close
public void close()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 interfaceEntityManagerFactory
- Specified by:
close
in interfaceSessionFactory
-
getCache
Description copied from interface:SessionFactoryImplementor
Obtain theCacheImplementor
.- Specified by:
getCache
in interfaceEntityManagerFactory
- Specified by:
getCache
in interfaceSessionFactory
- Specified by:
getCache
in interfaceSessionFactoryImplementor
- Returns:
- The direct cache access API.
-
getPersistenceUnitUtil
- Specified by:
getPersistenceUnitUtil
in interfaceEntityManagerFactory
-
getTransactionType
- Specified by:
getTransactionType
in interfaceEntityManagerFactory
-
addNamedQuery
- Specified by:
addNamedQuery
in interfaceEntityManagerFactory
-
unwrap
- Specified by:
unwrap
in interfaceEntityManagerFactory
-
addNamedEntityGraph
- Specified by:
addNamedEntityGraph
in interfaceEntityManagerFactory
-
getNamedQueries
- Specified by:
getNamedQueries
in interfaceEntityManagerFactory
-
getNamedEntityGraphs
- Specified by:
getNamedEntityGraphs
in interfaceEntityManagerFactory
-
runInTransaction
- Specified by:
runInTransaction
in interfaceEntityManagerFactory
-
callInTransaction
- Specified by:
callInTransaction
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
Description copied from interface:SessionFactoryImplementor
Obtain theStatisticsImplementor
.- Specified by:
getStatistics
in interfaceSessionFactory
- Specified by:
getStatistics
in interfaceSessionFactoryImplementor
- Returns:
- The statistics.
-
getFilterDefinition
Description copied from interface:SessionFactoryImplementor
Obtain the definition of a filter by name.- Specified by:
getFilterDefinition
in interfaceSessionFactory
- Specified by:
getFilterDefinition
in interfaceSessionFactoryImplementor
- Parameters:
filterName
- The name of a declared filter- Returns:
- The filter definition.
-
getAutoEnabledFilters
Description copied from interface:SessionFactoryImplementor
Obtain a collection ofFilterDefinition
s representing all the auto-enabled filters.- Specified by:
getAutoEnabledFilters
in interfaceSessionFactoryImplementor
-
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
-
getFetchProfile
Description copied from interface:SessionFactoryImplementor
Retrieve a fetch profile by name.- Specified by:
getFetchProfile
in interfaceSessionFactoryImplementor
- Parameters:
name
- The name of the profile to retrieve.- Returns:
- The profile definition
-
containsFetchProfileDefinition
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.
-
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.
-
getGenerator
Deprecated.Description copied from interface:SessionFactoryImplementor
Get the identifier generator for the hierarchy- Specified by:
getGenerator
in interfaceSessionFactoryImplementor
-
getRuntimeMetamodels
Description copied from interface:SessionFactoryImplementor
Obtain theRuntimeMetamodelsImplementor
- Specified by:
getRuntimeMetamodels
in interfaceSessionFactoryImplementor
-
getJpaMetamodel
Description copied from interface:SessionFactoryImplementor
Obtain theJpaMetamodel
- Specified by:
getJpaMetamodel
in interfaceSessionFactoryImplementor
-
getServiceRegistry
Description copied from interface:SessionFactoryImplementor
Access to theServiceRegistry
for thisSessionFactory
.- Specified by:
getServiceRegistry
in interfaceSessionFactoryImplementor
- Returns:
- The factory's ServiceRegistry
-
getEntityNotFoundDelegate
Description copied from interface:SessionFactoryImplementor
Obtain theEntityNotFoundDelegate
- Specified by:
getEntityNotFoundDelegate
in interfaceSessionFactoryImplementor
-
configuredInterceptor
@Deprecated public static Interceptor configuredInterceptor(Interceptor interceptor, SessionFactoryOptions options) -
configuredInterceptor
public static Interceptor configuredInterceptor(Interceptor interceptor, boolean explicitNoInterceptor, SessionFactoryOptions options) -
getCustomEntityDirtinessStrategy
Description copied from interface:SessionFactoryImplementor
Obtain theCustomEntityDirtinessStrategy
- Specified by:
getCustomEntityDirtinessStrategy
in interfaceSessionFactoryImplementor
-
getCurrentTenantIdentifierResolver
Description copied from interface:SessionFactoryImplementor
Obtain theCurrentTenantIdentifierResolver
- Specified by:
getCurrentTenantIdentifierResolver
in interfaceSessionFactoryImplementor
-
getTenantIdentifierJavaType
Description copied from interface:SessionFactoryImplementor
TheJavaType
to use for a tenant identifier.- Specified by:
getTenantIdentifierJavaType
in interfaceSessionFactoryImplementor
-
getWrapperOptions
Description copied from interface:SessionFactoryImplementor
Return an instance ofWrapperOptions
which is not backed by a session, and whose functionality is therefore incomplete.- Specified by:
getWrapperOptions
in interfaceSessionFactoryImplementor
-
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 interfaceEntityManagerFactory
- Specified by:
getSchemaManager
in interfaceSessionFactory
-
getMappingMetamodel
Description copied from interface:SessionFactoryImplementor
Obtain theMappingMetamodelImplementor
- Specified by:
getMappingMetamodel
in interfaceSessionFactoryImplementor
-
configuredInterceptor(Interceptor, boolean, SessionFactoryOptions)