Class SessionFactoryImpl
- All Implemented Interfaces:
EntityManagerFactory,Closeable,Serializable,AutoCloseable,Referenceable,Mapping,SessionFactoryImplementor,QueryParameterBindingTypeResolver,SqmCreationContext,SessionFactory,SqlAstCreationContext
SessionFactory API.
Exposes two interfaces:
SessionFactoryto the application, andSessionImplementor(an SPI interface) to other subsystems.
This class is thread-safe.
- Author:
- Gavin King, Steve Ebersole, Chris Cranford
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classNested classes/interfaces inherited from interface org.hibernate.engine.spi.SessionFactoryImplementor
SessionFactoryImplementor.DeserializationResolver<T extends SessionFactoryImplementor> -
Constructor Summary
ConstructorsConstructorDescriptionSessionFactoryImpl(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
Modifier and TypeMethodDescription<T> voidaddNamedEntityGraph(String graphName, EntityGraph<T> entityGraph) Add a named copy of the EntityGraph to the EntityManagerFactory.voidaddNamedQuery(String name, Query query) Define the query, typed query, or stored procedure query as a named query such that future query objects can be created from it using thecreateNamedQueryorcreateNamedStoredProcedureQuerymethod.voidaddObserver(SessionFactoryObserver observer) bestGuessEntityName(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) booleanDetermine if there is a fetch profile definition registered under the given name.Create a new application-managedEntityManager.createEntityManager(SynchronizationType synchronizationType) Create a new JTA application-managedEntityManagerwith the specified synchronization type.createEntityManager(SynchronizationType synchronizationType, Map map) Create a new JTA application-managedEntityManagerwith the specified synchronization type and map of properties.createEntityManager(Map map) Create a new application-managedEntityManagerwith the specified Map of properties.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.getCache()Obtain direct access to the underlying cache regions.getCollectionMetadata(String roleName) Obtains the current session, an instance ofSessionimplicitly associated with some context or scope.Obtain the set of names of alldefined fetch profiles.Obtain the set of names of alldefined filters.Deprecated.Get the EventEngine associated with this SessionFactorygetFetchProfile(String name) Retrieve fetch profile by name.getFilterDefinition(String filterName) Obtain the definition of a filter by name.getGenerator(String rootEntityName) Deprecated.getIdentifierGenerator(String rootEntityName) Deprecated.getIdentifierPropertyName(String className) getIdentifierType(String className) Get the JdbcServices.Access to the domain model metadataWhen creatingFetchreferences, defines a limit to how deep we should join for fetches.Return an instance ofMetamodelinterface for access to the metamodel of the persistence unit.getName()Access to the name (if one) assigned to the SessionFactoryReturn interface providing access to utility methods for the persistence unit.Get the properties and associated values that are in effect for the entity manager factory.getReferencedPropertyType(String className, String propertyName) ASchemaManagerwith the same default catalog and schema as pooled connections belonging to this factory.Access to the ServiceRegistry for this SessionFactory.Get the options used to build this factory.Retrieve the statistics for this factory.The java type to use for a tenant identifier.getUuid()Get the UUID for this SessionFactory.booleanisClosed()Is this factory already closed?booleanisOpen()Indicates whether the factory is open.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 (used by hibernate-envers)<T> TReturn an object of the specified type to allow access to the provider-specific API.protected voidObtain a session builder for creating newSessions with certain customized options.Obtain aStatelessSessionbuilder.Methods inherited from class org.hibernate.internal.QueryParameterBindingTypeResolverImpl
resolveParameterBindType, resolveParameterBindTypeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hibernate.query.spi.QueryParameterBindingTypeResolver
getMappingMetamodelMethods inherited from interface org.hibernate.SessionFactory
fromSession, fromStatelessSession, fromStatelessTransaction, fromTransaction, inSession, inStatelessSession, inStatelessTransaction, inTransactionMethods inherited from interface org.hibernate.engine.spi.SessionFactoryImplementor
getMappingMetamodel, getSessionFactory, resolveParameterBindType, resolveParameterBindTypeMethods inherited from interface org.hibernate.query.sqm.spi.SqmCreationContext
getNodeBuilder
-
Constructor Details
-
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 Details
-
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.
- Throws:
HibernateException- Indicates a problem opening the session; pretty rare here.
-
openTemporarySession
Description copied from interface:SessionFactoryImplementorGet a non-transactional "current" session (used by hibernate-envers)- Specified by:
openTemporarySessionin interfaceSessionFactoryImplementor- Throws:
HibernateException
-
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.
- Throws:
HibernateException- Indicates an issue locating a suitable current session.- See Also:
-
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
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 created 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 created stateless session.
-
addObserver
- Specified by:
addObserverin interfaceSessionFactoryImplementor
-
getProperties
Description copied from interface:EntityManagerFactoryGet the properties and associated values that are in effect for the entity manager factory. Changing the contents of the map does not change the configuration in effect.- Specified by:
getPropertiesin interfaceEntityManagerFactory- Returns:
- properties
-
validateNotClosed
protected void validateNotClosed() -
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:
-
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
- Specified by:
getTypeConfigurationin interfaceQueryParameterBindingTypeResolver- Specified by:
getTypeConfigurationin interfaceSessionFactoryImplementor- Specified by:
getTypeConfigurationin interfaceSqmCreationContext
-
getQueryEngine
- Specified by:
getQueryEnginein interfaceSessionFactoryImplementor- Specified by:
getQueryEnginein interfaceSqmCreationContext
-
getEventEngine
Description copied from interface:SessionFactoryImplementorGet the EventEngine associated with this SessionFactory- Specified by:
getEventEnginein interfaceSessionFactoryImplementor
-
getJdbcServices
Description copied from interface:SessionFactoryImplementorGet the JdbcServices.- Specified by:
getJdbcServicesin interfaceSessionFactoryImplementor- Returns:
- the JdbcServices
-
getSqlStringGenerationContext
- Specified by:
getSqlStringGenerationContextin interfaceSessionFactoryImplementor
-
getIdentifierGeneratorFactory
-
getDeserializationResolver
@Deprecated public SessionFactoryImplementor.DeserializationResolver<?> getDeserializationResolver()Deprecated.- Specified by:
getDeserializationResolverin 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:EntityManagerFactoryCreate a new application-managedEntityManager. This method returns a newEntityManagerinstance each time it is invoked. TheisOpenmethod will return true on the returned instance.- Specified by:
createEntityManagerin interfaceEntityManagerFactory- Returns:
- entity manager instance
-
createEntityManager
Description copied from interface:EntityManagerFactoryCreate a new application-managedEntityManagerwith the specified Map of properties. This method returns a newEntityManagerinstance each time it is invoked. TheisOpenmethod will return true on the returned instance.- Specified by:
createEntityManagerin interfaceEntityManagerFactory- Parameters:
map- properties for entity manager- Returns:
- entity manager instance
-
createEntityManager
Description copied from interface:EntityManagerFactoryCreate a new JTA application-managedEntityManagerwith the specified synchronization type. This method returns a newEntityManagerinstance each time it is invoked. TheisOpenmethod will return true on the returned instance.- Specified by:
createEntityManagerin interfaceEntityManagerFactory- Parameters:
synchronizationType- how and when the entity manager should be synchronized with the current JTA transaction- Returns:
- entity manager instance
-
createEntityManager
Description copied from interface:EntityManagerFactoryCreate a new JTA application-managedEntityManagerwith the specified synchronization type and map of properties. This method returns a newEntityManagerinstance each time it is invoked. TheisOpenmethod will return true on the returned instance.- Specified by:
createEntityManagerin interfaceEntityManagerFactory- Parameters:
synchronizationType- how and when the entity manager should be synchronized with the current JTA transactionmap- properties for entity manager- Returns:
- entity manager instance
-
getCriteriaBuilder
Description copied from interface:SessionFactory- Specified by:
getCriteriaBuilderin interfaceEntityManagerFactory- Specified by:
getCriteriaBuilderin interfaceSessionFactory- Specified by:
getCriteriaBuilderin interfaceSessionFactoryImplementor- Returns:
- CriteriaBuilder instance
- See Also:
-
getMetamodel
Description copied from interface:EntityManagerFactoryReturn an instance ofMetamodelinterface for access to the metamodel of the persistence unit.- Specified by:
getMetamodelin interfaceEntityManagerFactory- Specified by:
getMetamodelin interfaceSessionFactoryImplementor- Returns:
- Metamodel instance
-
isOpen
public boolean isOpen()Description copied from interface:EntityManagerFactoryIndicates whether the factory is open. Returns true until the factory has been closed.- Specified by:
isOpenin interfaceEntityManagerFactory- Returns:
- boolean indicating whether the factory is open
-
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:SessionFactoryGet 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
-
getIdentifierType
- Specified by:
getIdentifierTypein interfaceMapping- Throws:
MappingException
-
getIdentifierPropertyName
- Specified by:
getIdentifierPropertyNamein interfaceMapping- Throws:
MappingException
-
getCollectionMetadata
- Throws:
HibernateException
-
getReferencedPropertyType
public Type getReferencedPropertyType(String className, String propertyName) throws MappingException - Specified by:
getReferencedPropertyTypein interfaceMapping- Throws:
MappingException
-
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 interfaceCloseable- Specified by:
closein interfaceEntityManagerFactory- Specified by:
closein interfaceSessionFactory- Throws:
HibernateException- Indicates an issue closing the factory.
-
getCache
Description copied from interface:SessionFactoryObtain direct access to the underlying cache regions.- Specified by:
getCachein interfaceEntityManagerFactory- Specified by:
getCachein interfaceSessionFactory- Specified by:
getCachein interfaceSessionFactoryImplementor- Returns:
- The direct cache access API.
-
getPersistenceUnitUtil
Description copied from interface:EntityManagerFactoryReturn interface providing access to utility methods for the persistence unit.- Specified by:
getPersistenceUnitUtilin interfaceEntityManagerFactory- Returns:
PersistenceUnitUtilinterface
-
addNamedQuery
Description copied from interface:EntityManagerFactoryDefine the query, typed query, or stored procedure query as a named query such that future query objects can be created from it using thecreateNamedQueryorcreateNamedStoredProcedureQuerymethod.Any configuration of the query object (except for actual parameter binding) in effect when the named query is added is retained as part of the named query definition. This includes configuration information such as max results, hints, flush mode, lock mode, result set mapping information, and information about stored procedure parameters.
When the query is executed, information that can be set by means of the query APIs can be overridden. Information that is overridden does not affect the named query as registered with the entity manager factory, and thus does not affect subsequent query objects created from it by means of the
createNamedQueryorcreateNamedStoredProcedureQuerymethod.If a named query of the same name has been previously defined, either statically via metadata or via this method, that query definition is replaced.
- Specified by:
addNamedQueryin interfaceEntityManagerFactory- Parameters:
name- name for the queryquery- Query, TypedQuery, or StoredProcedureQuery object
-
unwrap
Description copied from interface:EntityManagerFactoryReturn an object of the specified type to allow access to the provider-specific API. If the provider's EntityManagerFactory implementation does not support the specified class, the PersistenceException is thrown.- Specified by:
unwrapin interfaceEntityManagerFactory- Parameters:
type- the class of the object to be returned. This is normally either the underlying EntityManagerFactory implementation class or an interface that it implements.- Returns:
- an instance of the specified class
-
addNamedEntityGraph
Description copied from interface:EntityManagerFactoryAdd a named copy of the EntityGraph to the EntityManagerFactory. If an entity graph with the same name already exists, it is replaced.- Specified by:
addNamedEntityGraphin interfaceEntityManagerFactory- Parameters:
graphName- name for the entity graphentityGraph- entity graph
-
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:SessionFactoryRetrieve the statistics for this factory.- Specified by:
getStatisticsin interfaceSessionFactory- Specified by:
getStatisticsin interfaceSessionFactoryImplementor- Returns:
- The statistics.
-
getFilterDefinition
Description copied from interface:SessionFactoryObtain the definition of a filter by name.- Specified by:
getFilterDefinitionin interfaceSessionFactory- Specified by:
getFilterDefinitionin 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
- Specified by:
getAutoEnabledFiltersin interfaceSessionFactoryImplementor
-
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.
-
getDefinedFilterNames
Description copied from interface:SessionFactoryObtain the set of names of alldefined filters.- Specified by:
getDefinedFilterNamesin interfaceSessionFactory- Returns:
- The set of filter names given by
FilterDefannotations
-
getDefinedFetchProfileNames
Description copied from interface:SessionFactoryObtain the set of names of alldefined fetch profiles.- Specified by:
getDefinedFetchProfileNamesin interfaceSessionFactory- Returns:
- The set of fetch profile names given by
FetchProfileannotations.
-
getIdentifierGenerator
Deprecated.Description copied from interface:SessionFactoryImplementorGet the identifier generator for the hierarchy- Specified by:
getIdentifierGeneratorin interfaceSessionFactoryImplementor
-
getGenerator
Deprecated.Description copied from interface:SessionFactoryImplementorGet the identifier generator for the hierarchy- Specified by:
getGeneratorin interfaceSessionFactoryImplementor
-
getRuntimeMetamodels
- Specified by:
getRuntimeMetamodelsin interfaceSessionFactoryImplementor
-
getJpaMetamodel
Description copied from interface:SqmCreationContextAccess to the domain model metadata- Specified by:
getJpaMetamodelin interfaceSqmCreationContext
-
getMaximumFetchDepth
Description copied from interface:SqlAstCreationContextWhen creatingFetchreferences, defines a limit to how deep we should join for fetches.- Specified by:
getMaximumFetchDepthin interfaceSqlAstCreationContext
-
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
- Specified by:
getEntityNotFoundDelegatein interfaceSessionFactoryImplementor
-
getFetchProfile
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
-
configuredInterceptor
@Deprecated public static Interceptor configuredInterceptor(Interceptor interceptor, SessionFactoryOptions options) -
configuredInterceptor
public static Interceptor configuredInterceptor(Interceptor interceptor, boolean explicitNoInterceptor, SessionFactoryOptions options) -
getCustomEntityDirtinessStrategy
- Specified by:
getCustomEntityDirtinessStrategyin interfaceSessionFactoryImplementor
-
getCurrentTenantIdentifierResolver
- Specified by:
getCurrentTenantIdentifierResolverin interfaceSessionFactoryImplementor
-
getTenantIdentifierJavaType
Description copied from interface:SessionFactoryImplementorThe java type to use for a tenant identifier.- Specified by:
getTenantIdentifierJavaTypein interfaceSessionFactoryImplementor
-
getFastSessionServices
- Specified by:
getFastSessionServicesin interfaceSessionFactoryImplementor- Returns:
- the
FastSessionServicesfor thisSessionFactory.
-
getWrapperOptions
- 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 interfaceSessionFactory
-