Package org.hibernate.internal
Class SessionFactoryImpl
- java.lang.Object
-
- org.hibernate.internal.SessionFactoryImpl
-
- All Implemented Interfaces:
jakarta.persistence.EntityManagerFactory,Closeable,Serializable,AutoCloseable,Referenceable,Mapping,SessionFactoryImplementor,QueryParameterBindingTypeResolver,SqmCreationContext,SessionFactory,SqlAstCreationContext
public class SessionFactoryImpl extends Object implements SessionFactoryImplementor
Concrete implementation of theSessionFactoryinterface. Has the following responsibilities- caches configuration settings (immutably)
- caches "compiled" mappings ie.
EntityPersisters andCollectionPersisters (immutable) - caches "compiled" queries (memory sensitive cache)
- manages
PreparedStatements - delegates JDBC
Connectionmanagement to theConnectionProvider - factory for instances of
SessionImpl
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSessionFactoryImpl.SessionBuilderImpl<T extends SessionBuilder>static classSessionFactoryImpl.StatelessSessionBuilderImpl-
Nested classes/interfaces inherited from interface org.hibernate.SessionFactory
SessionFactory.TransactionManagementException
-
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)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> voidaddNamedEntityGraph(String graphName, jakarta.persistence.EntityGraph<T> entityGraph)voidaddNamedQuery(String name, jakarta.persistence.Query query)voidaddObserver(SessionFactoryObserver observer)StringbestGuessEntityName(Object object)The best guess entity name for an entity not in an associationvoidclose()Closes the session factory, releasing all held resources.static InterceptorconfiguredInterceptor(Interceptor interceptor, boolean explicitNoInterceptor, SessionFactoryOptions options)static InterceptorconfiguredInterceptor(Interceptor interceptor, SessionFactoryOptions options)booleancontainsFetchProfileDefinition(String name)Determine if this session factory contains a fetch profile definition registered under the given name.SessioncreateEntityManager()SessioncreateEntityManager(jakarta.persistence.SynchronizationType synchronizationType)SessioncreateEntityManager(jakarta.persistence.SynchronizationType synchronizationType, Map map)SessioncreateEntityManager(Map map)RootGraphImplementor<?>findEntityGraphByName(String name)<T> List<jakarta.persistence.EntityGraph<? super T>>findEntityGraphsByType(Class<T> entityClass)Return allEntityGraphs registered for the given entity type.CacheImplementorgetCache()Obtain direct access to the underlying cache regions.CollectionMetadatagetCollectionMetadata(String roleName)NodeBuildergetCriteriaBuilder()SessiongetCurrentSession()Obtains the current session, an instance ofSessionimplicitly associated with some context.CurrentTenantIdentifierResolvergetCurrentTenantIdentifierResolver()CustomEntityDirtinessStrategygetCustomEntityDirtinessStrategy()Set<String>getDefinedFilterNames()Obtain the set of names of alldefined filters.SessionFactoryImplementor.DeserializationResolvergetDeserializationResolver()EntityNotFoundDelegategetEntityNotFoundDelegate()EventEnginegetEventEngine()Get the EventEngine associated with this SessionFactoryFastSessionServicesgetFastSessionServices()FetchProfilegetFetchProfile(String name)Retrieve fetch profile by name.FilterDefinitiongetFilterDefinition(String filterName)Obtain the definition of a filter by name.IdentifierGeneratorgetIdentifierGenerator(String rootEntityName)Get the identifier generator for the hierarchyIdentifierGeneratorFactorygetIdentifierGeneratorFactory()StringgetIdentifierPropertyName(String className)TypegetIdentifierType(String className)InterceptorgetInterceptor()JdbcServicesgetJdbcServices()Get the JdbcServices.JpaMetamodelImplementorgetJpaMetamodel()Access to the domain model metadataIntegergetMaximumFetchDepth()When creatingFetchreferences, defines a limit to how deep we should join for fetches.MetamodelImplementorgetMetamodel()StringgetName()Access to the name (if one) assigned to the SessionFactoryjakarta.persistence.PersistenceUnitUtilgetPersistenceUnitUtil()Map<String,Object>getProperties()QueryEnginegetQueryEngine()ReferencegetReference()TypegetReferencedPropertyType(String className, String propertyName)RuntimeMetamodelsImplementorgetRuntimeMetamodels()ServiceRegistryImplementorgetServiceRegistry()Access to the ServiceRegistry for this SessionFactory.SessionFactoryOptionsgetSessionFactoryOptions()Get the special options used to build the factory.SqlStringGenerationContextgetSqlStringGenerationContext()StatisticsImplementorgetStatistics()Retrieve the statistics for this factory.TypeConfigurationgetTypeConfiguration()StringgetUuid()Get the UUID for this SessionFactory.WrapperOptionsgetWrapperOptions()booleanisClosed()Is this factory already closed?booleanisOpen()SessionopenSession()Open aSession.StatelessSessionopenStatelessSession()Open a new stateless session.StatelessSessionopenStatelessSession(Connection connection)Open a new stateless session, utilizing the specified JDBCConnection.SessionopenTemporarySession()Get a non-transactional "current" session (used by hibernate-envers)<T> BindableType<T>resolveParameterBindType(Class<T> javaType)<T> BindableType<? extends T>resolveParameterBindType(T bindValue)<T> Tunwrap(Class<T> type)protected voidvalidateNotClosed()SessionBuilderImplementorwithOptions()Obtain a session builder for creating newSessions with certain customized options.StatelessSessionBuilderwithStatelessOptions()Obtain aStatelessSessionbuilder.-
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, fromTransaction, inSession, inTransaction
-
Methods inherited from interface org.hibernate.engine.spi.SessionFactoryImplementor
getMappingMetamodel, getSessionFactory
-
Methods inherited from interface org.hibernate.query.sqm.spi.SqmCreationContext
getNodeBuilder
-
-
-
-
Constructor Detail
-
SessionFactoryImpl
public SessionFactoryImpl(MetadataImplementor bootMetamodel, SessionFactoryOptions options)
-
-
Method Detail
-
openSession
public Session openSession() throws HibernateException
Description copied from interface:SessionFactoryOpen aSession. Any JDBCconnectionwill be obtained lazily from theConnectionProvideras needed to perform requested work.- Specified by:
openSessionin interfaceSessionFactory- Returns:
- The created session.
- Throws:
HibernateException- Indicates a problem opening the session; pretty rare here.
-
openTemporarySession
public Session openTemporarySession() throws HibernateException
Description copied from interface:SessionFactoryImplementorGet a non-transactional "current" session (used by hibernate-envers)- Specified by:
openTemporarySessionin interfaceSessionFactoryImplementor- Throws:
HibernateException
-
getCurrentSession
public Session getCurrentSession() throws HibernateException
Description copied from interface:SessionFactoryObtains the current session, an instance ofSessionimplicitly associated with some context. 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 is configured, thenJTASessionContextis used.- Specified by:
getCurrentSessionin interfaceSessionFactory- Returns:
- The current session.
- Throws:
HibernateException- Indicates an issue locating a suitable current session.
-
withOptions
public SessionBuilderImplementor withOptions()
Description copied from interface:SessionFactoryObtain a session builder for creating newSessions with certain customized options.- Specified by:
withOptionsin interfaceSessionFactory- Specified by:
withOptionsin interfaceSessionFactoryImplementor- Returns:
- The session builder
-
withStatelessOptions
public StatelessSessionBuilder withStatelessOptions()
Description copied from interface:SessionFactoryObtain aStatelessSessionbuilder.- Specified by:
withStatelessOptionsin interfaceSessionFactory- Returns:
- The stateless session builder
-
openStatelessSession
public StatelessSession openStatelessSession()
Description copied from interface:SessionFactoryOpen a new stateless session.- Specified by:
openStatelessSessionin interfaceSessionFactory- Returns:
- The created stateless session.
-
openStatelessSession
public StatelessSession openStatelessSession(Connection connection)
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 created stateless session.
-
addObserver
public void addObserver(SessionFactoryObserver observer)
- Specified by:
addObserverin interfaceSessionFactoryImplementor
-
getProperties
public Map<String,Object> getProperties()
- Specified by:
getPropertiesin interfacejakarta.persistence.EntityManagerFactory
-
validateNotClosed
protected void validateNotClosed()
-
getUuid
public String getUuid()
Description copied from interface:SessionFactoryImplementorGet the UUID for this SessionFactory.The value is generated as a
UUID, but kept as a String.- Specified by:
getUuidin interfaceSessionFactoryImplementor- Returns:
- The UUID for this SessionFactory.
- See Also:
SessionFactoryRegistry.getSessionFactory(java.lang.String)
-
getName
public String getName()
Description copied from interface:SessionFactoryImplementorAccess to the name (if one) assigned to the SessionFactory- Specified by:
getNamein interfaceSessionFactoryImplementor- Returns:
- The name for the SessionFactory
-
getTypeConfiguration
public TypeConfiguration getTypeConfiguration()
- Specified by:
getTypeConfigurationin interfaceQueryParameterBindingTypeResolver- Specified by:
getTypeConfigurationin interfaceSessionFactoryImplementor
-
getQueryEngine
public QueryEngine getQueryEngine()
- Specified by:
getQueryEnginein interfaceSessionFactoryImplementor- Specified by:
getQueryEnginein interfaceSqmCreationContext
-
getEventEngine
public EventEngine getEventEngine()
Description copied from interface:SessionFactoryImplementorGet the EventEngine associated with this SessionFactory- Specified by:
getEventEnginein interfaceSessionFactoryImplementor
-
getJdbcServices
public JdbcServices getJdbcServices()
Description copied from interface:SessionFactoryImplementorGet the JdbcServices.- Specified by:
getJdbcServicesin interfaceSessionFactoryImplementor- Returns:
- the JdbcServices
-
getSqlStringGenerationContext
public SqlStringGenerationContext getSqlStringGenerationContext()
- Specified by:
getSqlStringGenerationContextin interfaceSessionFactoryImplementor
-
getIdentifierGeneratorFactory
public IdentifierGeneratorFactory getIdentifierGeneratorFactory()
-
getDeserializationResolver
public SessionFactoryImplementor.DeserializationResolver getDeserializationResolver()
- Specified by:
getDeserializationResolverin interfaceSessionFactoryImplementor
-
findEntityGraphsByType
public <T> List<jakarta.persistence.EntityGraph<? super T>> findEntityGraphsByType(Class<T> entityClass)
Description copied from interface:SessionFactoryReturn allEntityGraphs registered for the given entity type.- Specified by:
findEntityGraphsByTypein interfaceSessionFactory- See Also:
EntityManagerFactory.addNamedEntityGraph(java.lang.String, jakarta.persistence.EntityGraph<T>)
-
createEntityManager
public Session createEntityManager()
- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public Session createEntityManager(Map map)
- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public Session createEntityManager(jakarta.persistence.SynchronizationType synchronizationType)
- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public Session createEntityManager(jakarta.persistence.SynchronizationType synchronizationType, Map map)
- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory
-
getCriteriaBuilder
public NodeBuilder getCriteriaBuilder()
- Specified by:
getCriteriaBuilderin interfacejakarta.persistence.EntityManagerFactory- Specified by:
getCriteriaBuilderin interfaceSessionFactoryImplementor
-
getMetamodel
public MetamodelImplementor getMetamodel()
- Specified by:
getMetamodelin interfacejakarta.persistence.EntityManagerFactory- Specified by:
getMetamodelin interfaceSessionFactoryImplementor
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejakarta.persistence.EntityManagerFactory
-
findEntityGraphByName
public RootGraphImplementor<?> findEntityGraphByName(String name)
- Specified by:
findEntityGraphByNamein interfaceSessionFactoryImplementor
-
bestGuessEntityName
public String bestGuessEntityName(Object object)
Description copied from interface:SessionFactoryImplementorThe best guess entity name for an entity not in an association- Specified by:
bestGuessEntityNamein interfaceSessionFactoryImplementor
-
getSessionFactoryOptions
public SessionFactoryOptions getSessionFactoryOptions()
Description copied from interface:SessionFactoryGet the special options used to build the factory.- Specified by:
getSessionFactoryOptionsin interfaceSessionFactory- Returns:
- The special options used to build the factory.
-
getInterceptor
public Interceptor getInterceptor()
-
getReference
public Reference getReference()
- Specified by:
getReferencein interfaceReferenceable
-
getIdentifierType
public Type getIdentifierType(String className) throws MappingException
- Specified by:
getIdentifierTypein interfaceMapping- Throws:
MappingException
-
getIdentifierPropertyName
public String getIdentifierPropertyName(String className) throws MappingException
- Specified by:
getIdentifierPropertyNamein 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:
getReferencedPropertyTypein interfaceMapping- Throws:
MappingException
-
close
public void close() throws HibernateExceptionCloses 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 interfaceCloseable- Specified by:
closein interfacejakarta.persistence.EntityManagerFactory- Specified by:
closein interfaceSessionFactory- Throws:
HibernateException- Indicates an issue closing the factory.
-
getCache
public CacheImplementor getCache()
Description copied from interface:SessionFactoryObtain direct access to the underlying cache regions.- Specified by:
getCachein interfacejakarta.persistence.EntityManagerFactory- Specified by:
getCachein interfaceSessionFactory- Specified by:
getCachein interfaceSessionFactoryImplementor- Returns:
- The direct cache access API.
-
getPersistenceUnitUtil
public jakarta.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
- Specified by:
getPersistenceUnitUtilin interfacejakarta.persistence.EntityManagerFactory
-
addNamedQuery
public void addNamedQuery(String name, jakarta.persistence.Query query)
- Specified by:
addNamedQueryin interfacejakarta.persistence.EntityManagerFactory
-
unwrap
public <T> T unwrap(Class<T> type)
- Specified by:
unwrapin interfacejakarta.persistence.EntityManagerFactory
-
addNamedEntityGraph
public <T> void addNamedEntityGraph(String graphName, jakarta.persistence.EntityGraph<T> entityGraph)
- Specified by:
addNamedEntityGraphin interfacejakarta.persistence.EntityManagerFactory
-
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
public StatisticsImplementor getStatistics()
Description copied from interface:SessionFactoryRetrieve the statistics for this factory.- Specified by:
getStatisticsin interfaceSessionFactory- Specified by:
getStatisticsin interfaceSessionFactoryImplementor- Returns:
- The statistics.
-
getFilterDefinition
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException
Description copied from interface:SessionFactoryObtain the definition of a filter by name.- Specified by:
getFilterDefinitionin interfaceSessionFactory- 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.
-
containsFetchProfileDefinition
public boolean containsFetchProfileDefinition(String name)
Description copied from interface:SessionFactoryDetermine if this session factory contains 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.
-
getDefinedFilterNames
public Set<String> getDefinedFilterNames()
Description copied from interface:SessionFactoryObtain the set of names of alldefined filters.- Specified by:
getDefinedFilterNamesin interfaceSessionFactory- Returns:
- The set of filter names.
-
getIdentifierGenerator
public IdentifierGenerator getIdentifierGenerator(String rootEntityName)
Description copied from interface:SessionFactoryImplementorGet the identifier generator for the hierarchy- Specified by:
getIdentifierGeneratorin interfaceSessionFactoryImplementor
-
getRuntimeMetamodels
public RuntimeMetamodelsImplementor getRuntimeMetamodels()
- Specified by:
getRuntimeMetamodelsin interfaceSessionFactoryImplementor
-
getJpaMetamodel
public JpaMetamodelImplementor getJpaMetamodel()
Description copied from interface:SqmCreationContextAccess to the domain model metadata- Specified by:
getJpaMetamodelin interfaceSqmCreationContext
-
getMaximumFetchDepth
public Integer getMaximumFetchDepth()
Description copied from interface:SqlAstCreationContextWhen creatingFetchreferences, defines a limit to how deep we should join for fetches.- Specified by:
getMaximumFetchDepthin interfaceSqlAstCreationContext
-
getServiceRegistry
public ServiceRegistryImplementor getServiceRegistry()
Description copied from interface:SessionFactoryImplementorAccess to the ServiceRegistry for this SessionFactory.- Specified by:
getServiceRegistryin interfaceSessionFactoryImplementor- Specified by:
getServiceRegistryin interfaceSqlAstCreationContext- Specified by:
getServiceRegistryin interfaceSqmCreationContext- Returns:
- The factory's ServiceRegistry
-
getEntityNotFoundDelegate
public EntityNotFoundDelegate getEntityNotFoundDelegate()
- Specified by:
getEntityNotFoundDelegatein interfaceSessionFactoryImplementor
-
getFetchProfile
public FetchProfile getFetchProfile(String name)
Description copied from interface:SessionFactoryImplementorRetrieve fetch profile by name.- Specified by:
getFetchProfilein interfaceSessionFactoryImplementor- Parameters:
name- The name of the profile to retrieve.- Returns:
- The profile definition
-
resolveParameterBindType
public <T> BindableType<? extends T> resolveParameterBindType(T bindValue)
- Specified by:
resolveParameterBindTypein interfaceQueryParameterBindingTypeResolver
-
resolveParameterBindType
public <T> BindableType<T> resolveParameterBindType(Class<T> javaType)
- Specified by:
resolveParameterBindTypein interfaceQueryParameterBindingTypeResolver
-
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:
getCustomEntityDirtinessStrategyin interfaceSessionFactoryImplementor
-
getCurrentTenantIdentifierResolver
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver()
- Specified by:
getCurrentTenantIdentifierResolverin interfaceSessionFactoryImplementor
-
getFastSessionServices
public FastSessionServices getFastSessionServices()
- Specified by:
getFastSessionServicesin interfaceSessionFactoryImplementor- Returns:
- the FastSessionServices for this SessionFactory.
-
getWrapperOptions
public WrapperOptions getWrapperOptions()
- Specified by:
getWrapperOptionsin interfaceSessionFactoryImplementor
-
-