Class SessionFactoryImpl
- All Implemented Interfaces:
EntityManagerFactory,Serializable,AutoCloseable,Referenceable,SessionFactoryImplementor,SessionFactory
SessionFactory API.
Exposes two interfaces:
SessionFactoryto 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 classstatic class -
Constructor Summary
ConstructorsConstructorDescriptionSessionFactoryImpl(MetadataImplementor bootMetamodel, SessionFactoryOptions options, BootstrapContext bootstrapContext) -
Method Summary
Modifier and TypeMethodDescription<T> voidaddNamedEntityGraph(String graphName, EntityGraph<T> entityGraph) voidaddNamedQuery(String name, Query query) <R> TypedQueryReference<R> addNamedQuery(String name, TypedQuery<R> query) Add or override the definition of a named query, returning a reference to the query.voidaddObserver(SessionFactoryObserver observer) Register aSessionFactoryObserverof this factory.bestGuessEntityName(Object object) The best guess entity name for an entity not in an association<R> RcallInTransaction(Function<EntityManager, R> work) voidclose()Closes the session factory, releasing all held resources.static InterceptorconfiguredInterceptor(Interceptor interceptor, boolean explicitNoInterceptor, SessionFactoryOptions options) static InterceptorconfiguredInterceptor(Interceptor interceptor, SessionFactoryOptions options) Deprecated.booleanDetermine 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 anEntityGraphwhich may be used from loading a dynamic entity withEntityManager.find(EntityGraph, Object, FindOption...).findEntityGraphByName(String name) Return the rootEntityGraphwith the given name, ornullif there is no graph with the given name.<T> List<EntityGraph<? super T>> findEntityGraphsByType(Class<T> entityClass) Return allEntityGraphs registered for the given entity type.Obtain a collection ofFilterDefinitions representing all the auto-enabled filters.getCache()Obtain theCacheImplementor.Obtain theClassLoaderService.Obtains the current session, an instance ofSessionimplicitly associated with some context or scope.Obtain theCurrentTenantIdentifierResolverObtain theCustomEntityDirtinessStrategyObtain the set of names of all defined fetch profiles.Obtain the set of names of all defined filters.Obtain theEntityCopyObserverFactoryservice.Obtain theEntityNotFoundDelegateGet the EventEngine associated with this SessionFactoryAccess to the event listener groups.Obtain theEventListenerRegistryservice.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 theJdbcServicesservice.Obtain theJdbcServicesservice.The JNDI name, used to bind theSessionFactoryto JNDI.Obtain theJpaMetamodelObtain theManagedBeanRegistryservice.Obtain theMappingMetamodelImplementorgetName()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 theParameterMarkerStrategyservice.Obtain theQueryEngineObtain theRuntimeMetamodelsImplementorASchemaManagerwith the same default catalog and schema as pooled connections belonging to this factory.Access to theServiceRegistryfor thisSessionFactory.Get the options used to build this factory.Obtain theSqlStringGenerationContext.Obtain theSqlTranslationEngineObtain theStatisticsImplementor.TheJavaTypeto use for a tenant identifier.Obtain theTypeConfigurationgetUuid()The UUID assigned to thisSessionFactory.Return an instance ofWrapperOptionswhich is not backed by a session, and whose functionality is therefore incomplete.booleanisClosed()Is this factory already closed?booleanisOpen()OverridesSessionFactory.openSession()to widen the return type: this is useful for internal code depending onSessionFactoryImplementoras 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> Tprotected voidObtain a session builder for creating new instances ofSessionwith certain customized options.Obtain aStatelessSessionbuilder.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hibernate.SessionFactory
fromSession, fromStatelessSession, fromStatelessTransaction, fromTransaction, inSession, inStatelessSession, inStatelessTransaction, inTransaction, parseEntityGraph, parseEntityGraph, parseEntityGraphMethods inherited from interface org.hibernate.engine.spi.SessionFactoryImplementor
createEntityGraph
-
Constructor Details
-
SessionFactoryImpl
public SessionFactoryImpl(MetadataImplementor bootMetamodel, SessionFactoryOptions options, BootstrapContext bootstrapContext)
-
-
Method Details
-
getEventListenerGroups
Description copied from interface:SessionFactoryImplementorAccess to the event listener groups.- Specified by:
getEventListenerGroupsin interfaceSessionFactoryImplementor
-
getParameterMarkerStrategy
Description copied from interface:SessionFactoryImplementorObtain theParameterMarkerStrategyservice.- Specified by:
getParameterMarkerStrategyin interfaceSessionFactoryImplementor
-
getJdbcValuesMappingProducerProvider
Description copied from interface:SessionFactoryImplementorObtain theJdbcServicesservice.- Specified by:
getJdbcValuesMappingProducerProviderin interfaceSessionFactoryImplementor
-
getEntityCopyObserver
Description copied from interface:SessionFactoryImplementorObtain theEntityCopyObserverFactoryservice.- Specified by:
getEntityCopyObserverin interfaceSessionFactoryImplementor
-
getClassLoaderService
Description copied from interface:SessionFactoryImplementorObtain theClassLoaderService.- Specified by:
getClassLoaderServicein interfaceSessionFactoryImplementor
-
getManagedBeanRegistry
Description copied from interface:SessionFactoryImplementorObtain theManagedBeanRegistryservice.- Specified by:
getManagedBeanRegistryin interfaceSessionFactoryImplementor
-
getEventListenerRegistry
Description copied from interface:SessionFactoryImplementorObtain theEventListenerRegistryservice.- Specified by:
getEventListenerRegistryin interfaceSessionFactoryImplementor
-
openSession
Description copied from interface:SessionFactoryImplementorOverridesSessionFactory.openSession()to widen the return type: this is useful for internal code depending onSessionFactoryImplementoras it would otherwise need to frequently resort to casting to the internal contract.- Specified by:
openSessionin interfaceSessionFactory- Specified by:
openSessionin interfaceSessionFactoryImplementor- Returns:
- the opened
Session.
-
openTemporarySession
Description copied from interface:SessionFactoryImplementorGet a non-transactional "current" session.- Specified by:
openTemporarySessionin interfaceSessionFactoryImplementor
-
getCurrentSession
Description copied from interface:SessionFactoryObtains the current session, an instance ofSessionimplicitly 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
CurrentSessionContextis explicitly configured, but JTA support is enabled, thenJTASessionContextis used, and the current session is scoped to the active JTA transaction.- Specified by:
getCurrentSessionin interfaceSessionFactory- Returns:
- The current session.
- See Also:
-
withOptions
Description copied from interface:SessionFactoryImplementorObtain a session builder for creating new instances ofSessionwith certain customized options.- Specified by:
withOptionsin interfaceSessionFactory- Specified by:
withOptionsin interfaceSessionFactoryImplementor- Returns:
- The session builder
-
withStatelessOptions
Description copied from interface:SessionFactoryObtain aStatelessSessionbuilder.- Specified by:
withStatelessOptionsin interfaceSessionFactory- Returns:
- The stateless session builder
-
openStatelessSession
Description copied from interface:SessionFactoryOpen a new stateless session.- Specified by:
openStatelessSessionin interfaceSessionFactory- Returns:
- The new stateless session.
-
openStatelessSession
Description copied from interface:SessionFactoryOpen a new stateless session, utilizing the specified JDBCConnection.- Specified by:
openStatelessSessionin interfaceSessionFactory- Parameters:
connection- Connection provided by the application.- Returns:
- The new stateless session.
-
addObserver
Description copied from interface:SessionFactoryImplementorRegister aSessionFactoryObserverof this factory.- Specified by:
addObserverin interfaceSessionFactoryImplementor
-
getProperties
- Specified by:
getPropertiesin interfaceEntityManagerFactory
-
validateNotClosed
protected void validateNotClosed() -
getUuid
Description copied from interface:SessionFactoryImplementorThe UUID assigned to thisSessionFactory.The value is generated as a
UUID, but kept as a string.- Specified by:
getUuidin interfaceSessionFactoryImplementor- See Also:
-
getName
Description copied from interface:SessionFactoryThe 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:
getNamein interfaceEntityManagerFactory- Specified by:
getNamein interfaceSessionFactory- See Also:
-
getJndiName
Description copied from interface:SessionFactoryThe JNDI name, used to bind theSessionFactoryto JNDI.- Specified by:
getJndiNamein interfaceSessionFactory
-
getTypeConfiguration
Description copied from interface:SessionFactoryImplementorObtain theTypeConfiguration- Specified by:
getTypeConfigurationin interfaceSessionFactoryImplementor
-
getQueryEngine
Description copied from interface:SessionFactoryImplementorObtain theQueryEngine- Specified by:
getQueryEnginein interfaceSessionFactoryImplementor
-
getSqlTranslationEngine
Description copied from interface:SessionFactoryImplementorObtain theSqlTranslationEngine- Specified by:
getSqlTranslationEnginein interfaceSessionFactoryImplementor
-
getEventEngine
Description copied from interface:SessionFactoryImplementorGet the EventEngine associated with this SessionFactory- Specified by:
getEventEnginein interfaceSessionFactoryImplementor
-
getJdbcServices
Description copied from interface:SessionFactoryImplementorObtain theJdbcServicesservice.- Specified by:
getJdbcServicesin interfaceSessionFactoryImplementor
-
getSqlStringGenerationContext
Description copied from interface:SessionFactoryImplementorObtain theSqlStringGenerationContext.- Specified by:
getSqlStringGenerationContextin interfaceSessionFactoryImplementor
-
findEntityGraphsByType
Description copied from interface:SessionFactoryReturn allEntityGraphs registered for the given entity type.- Specified by:
findEntityGraphsByTypein interfaceSessionFactory- See Also:
-
createEntityManager
Description copied from interface:SessionFactoryCreate a newSession.- Specified by:
createEntityManagerin interfaceEntityManagerFactory- Specified by:
createEntityManagerin interfaceSessionFactory
-
createEntityManager
Description copied from interface:SessionFactoryCreate a newSession, with the given properties.- Specified by:
createEntityManagerin interfaceEntityManagerFactory- Specified by:
createEntityManagerin interfaceSessionFactory
-
createEntityManager
Description copied from interface:SessionFactoryCreate a newSession, with the given synchronization type.- Specified by:
createEntityManagerin interfaceEntityManagerFactory- Specified by:
createEntityManagerin interfaceSessionFactory
-
createEntityManager
Description copied from interface:SessionFactory- Specified by:
createEntityManagerin interfaceEntityManagerFactory- Specified by:
createEntityManagerin interfaceSessionFactory
-
getCriteriaBuilder
Description copied from interface:SessionFactory- Specified by:
getCriteriaBuilderin interfaceEntityManagerFactory- Specified by:
getCriteriaBuilderin interfaceSessionFactory- See Also:
-
getMetamodel
- Specified by:
getMetamodelin interfaceEntityManagerFactory
-
isOpen
public boolean isOpen()- Specified by:
isOpenin interfaceEntityManagerFactory
-
createGraphForDynamicEntity
Description copied from interface:SessionFactoryCreate anEntityGraphwhich 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:
createGraphForDynamicEntityin interfaceSessionFactory- Specified by:
createGraphForDynamicEntityin interfaceSessionFactoryImplementor- Parameters:
entityName- The name of the dynamic entity- See Also:
-
findEntityGraphByName
Description copied from interface:SessionFactoryReturn the rootEntityGraphwith the given name, ornullif there is no graph with the given name.- Specified by:
findEntityGraphByNamein interfaceSessionFactory- Specified by:
findEntityGraphByNamein interfaceSessionFactoryImplementor- Parameters:
name- the name given to someNamedEntityGraph- Returns:
- an instance of
RootGraph - See Also:
-
bestGuessEntityName
Description copied from interface:SessionFactoryImplementorThe best guess entity name for an entity not in an association- Specified by:
bestGuessEntityNamein interfaceSessionFactoryImplementor
-
getSessionFactoryOptions
Description copied from interface:SessionFactoryImplementorGet the options used to build this factory.- Specified by:
getSessionFactoryOptionsin interfaceSessionFactory- Specified by:
getSessionFactoryOptionsin interfaceSessionFactoryImplementor- Returns:
- The special options used to build the factory.
-
getInterceptor
-
getReference
- Specified by:
getReferencein 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceEntityManagerFactory- Specified by:
closein interfaceSessionFactory
-
getCache
Description copied from interface:SessionFactoryImplementorObtain theCacheImplementor.- Specified by:
getCachein interfaceEntityManagerFactory- Specified by:
getCachein interfaceSessionFactory- Specified by:
getCachein interfaceSessionFactoryImplementor- Returns:
- The direct cache access API.
-
getPersistenceUnitUtil
- Specified by:
getPersistenceUnitUtilin interfaceEntityManagerFactory
-
getTransactionType
- Specified by:
getTransactionTypein interfaceEntityManagerFactory
-
addNamedQuery
- Specified by:
addNamedQueryin interfaceEntityManagerFactory
-
addNamedQuery
Description copied from interface:SessionFactoryAdd or override the definition of a named query, returning a reference to the query. Settings such as first and max results, hints, flush mode, cache mode, timeout, and lock options are preserved as part of the named query definition. Any arguments bound to query parameters are discarded.- Specified by:
addNamedQueryin interfaceSessionFactory- Parameters:
name- the name to be assigned to the queryquery- the query, including first and max results, hints, flush mode, cache mode, timeout, and lock options- See Also:
-
unwrap
- Specified by:
unwrapin interfaceEntityManagerFactory
-
addNamedEntityGraph
- Specified by:
addNamedEntityGraphin interfaceEntityManagerFactory
-
getNamedQueries
- Specified by:
getNamedQueriesin interfaceEntityManagerFactory
-
getNamedEntityGraphs
- Specified by:
getNamedEntityGraphsin interfaceEntityManagerFactory
-
runInTransaction
- Specified by:
runInTransactionin interfaceEntityManagerFactory
-
callInTransaction
- Specified by:
callInTransactionin interfaceEntityManagerFactory
-
isClosed
public boolean isClosed()Description copied from interface:SessionFactoryIs this factory already closed?- Specified by:
isClosedin interfaceSessionFactory- Returns:
- True if this factory is already closed; false otherwise.
-
getStatistics
Description copied from interface:SessionFactoryImplementorObtain theStatisticsImplementor.- Specified by:
getStatisticsin interfaceSessionFactory- Specified by:
getStatisticsin interfaceSessionFactoryImplementor- Returns:
- The statistics.
-
getFilterDefinition
Description copied from interface:SessionFactoryImplementorObtain the definition of a filter by name.- Specified by:
getFilterDefinitionin interfaceSessionFactory- Specified by:
getFilterDefinitionin interfaceSessionFactoryImplementor- Parameters:
filterName- The name of a declared filter- Returns:
- The filter definition.
-
getAutoEnabledFilters
Description copied from interface:SessionFactoryImplementorObtain a collection ofFilterDefinitions representing all the auto-enabled filters.- Specified by:
getAutoEnabledFiltersin interfaceSessionFactoryImplementor
-
getDefinedFilterNames
Description copied from interface:SessionFactoryObtain the set of names of all defined filters.- Specified by:
getDefinedFilterNamesin interfaceSessionFactory- Returns:
- The set of filter names given by
FilterDefannotations
-
getFetchProfile
Description copied from interface:SessionFactoryImplementorRetrieve a fetch profile by name.- Specified by:
getFetchProfilein interfaceSessionFactoryImplementor- Parameters:
name- The name of the profile to retrieve.- Returns:
- The profile definition
-
containsFetchProfileDefinition
Description copied from interface:SessionFactoryDetermine if there is a fetch profile definition registered under the given name.- Specified by:
containsFetchProfileDefinitionin interfaceSessionFactory- Parameters:
name- The name to check- Returns:
- True if there is such a fetch profile; false otherwise.
-
getDefinedFetchProfileNames
Description copied from interface:SessionFactoryObtain the set of names of all defined fetch profiles.- Specified by:
getDefinedFetchProfileNamesin interfaceSessionFactory- Returns:
- The set of fetch profile names given by
FetchProfileannotations.
-
getGenerator
Deprecated.Description copied from interface:SessionFactoryImplementorGet the identifier generator for the hierarchy- Specified by:
getGeneratorin interfaceSessionFactoryImplementor
-
getRuntimeMetamodels
Description copied from interface:SessionFactoryImplementorObtain theRuntimeMetamodelsImplementor- Specified by:
getRuntimeMetamodelsin interfaceSessionFactoryImplementor
-
getJpaMetamodel
Description copied from interface:SessionFactoryImplementorObtain theJpaMetamodel- Specified by:
getJpaMetamodelin interfaceSessionFactoryImplementor
-
getServiceRegistry
Description copied from interface:SessionFactoryImplementorAccess to theServiceRegistryfor thisSessionFactory.- Specified by:
getServiceRegistryin interfaceSessionFactoryImplementor- Returns:
- The factory's ServiceRegistry
-
getEntityNotFoundDelegate
Description copied from interface:SessionFactoryImplementorObtain theEntityNotFoundDelegate- Specified by:
getEntityNotFoundDelegatein 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:SessionFactoryImplementorObtain theCustomEntityDirtinessStrategy- Specified by:
getCustomEntityDirtinessStrategyin interfaceSessionFactoryImplementor
-
getCurrentTenantIdentifierResolver
Description copied from interface:SessionFactoryImplementorObtain theCurrentTenantIdentifierResolver- Specified by:
getCurrentTenantIdentifierResolverin interfaceSessionFactoryImplementor
-
getTenantIdentifierJavaType
Description copied from interface:SessionFactoryImplementorTheJavaTypeto use for a tenant identifier.- Specified by:
getTenantIdentifierJavaTypein interfaceSessionFactoryImplementor
-
getWrapperOptions
Description copied from interface:SessionFactoryImplementorReturn an instance ofWrapperOptionswhich is not backed by a session, and whose functionality is therefore incomplete.- Specified by:
getWrapperOptionsin interfaceSessionFactoryImplementor
-
getSchemaManager
Description copied from interface:SessionFactoryASchemaManagerwith the same default catalog and schema as pooled connections belonging to this factory. Intended mostly as a convenience for writing tests.- Specified by:
getSchemaManagerin interfaceEntityManagerFactory- Specified by:
getSchemaManagerin interfaceSessionFactory
-
getMappingMetamodel
Description copied from interface:SessionFactoryImplementorObtain theMappingMetamodelImplementor- Specified by:
getMappingMetamodelin interfaceSessionFactoryImplementor
-
configuredInterceptor(Interceptor, boolean, SessionFactoryOptions)