Package org.hibernate
Interface SessionFactory
-
- All Superinterfaces:
AutoCloseable,Closeable,EntityManagerFactory,HibernateEntityManagerFactory,Referenceable,Serializable
- All Known Subinterfaces:
SessionFactoryImplementor
- All Known Implementing Classes:
SessionFactoryDelegatingImpl
public interface SessionFactory extends EntityManagerFactory, HibernateEntityManagerFactory, Referenceable, Serializable, Closeable
The main contract here is the creation ofSessioninstances. Usually an application has a singleSessionFactoryinstance and threads servicing client requests obtainSessioninstances from this factory. The internal state of aSessionFactoryis immutable. Once it is created this internal state is set. This internal state includes all of the metadata about Object/Relational Mapping. Implementors must be threadsafe.- See Also:
Configuration
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidclose()Destroy this SessionFactory and release all resources (caches, connection pools, etc).booleancontainsFetchProfileDefinition(String name)Determine if this session factory contains a fetch profile definition registered under the given name.Map<String,ClassMetadata>getAllClassMetadata()Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadMapgetAllCollectionMetadata()Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadCachegetCache()Obtain direct access to the underlying cache regions.ClassMetadatagetClassMetadata(Class entityClass)Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadClassMetadatagetClassMetadata(String entityName)Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadCollectionMetadatagetCollectionMetadata(String roleName)Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadSessiongetCurrentSession()Obtains the current session.SetgetDefinedFilterNames()Obtain a set of the names of all filters defined on this SessionFactory.FilterDefinitiongetFilterDefinition(String filterName)Obtain the definition of a filter by name.SessionFactoryOptionsgetSessionFactoryOptions()Get the special options used to build the factory.StatisticsgetStatistics()Retrieve the statistics for this factory.TypeHelpergetTypeHelper()Retrieve this factory'sTypeHelper.booleanisClosed()Is this factory already closed?SessionopenSession()Open aSession.StatelessSessionopenStatelessSession()Open a new stateless session.StatelessSessionopenStatelessSession(Connection connection)Open a new stateless session, utilizing the specified JDBCConnection.SessionBuilderwithOptions()Obtain aSessionbuilder.StatelessSessionBuilderwithStatelessOptions()Obtain aStatelessSessionbuilder.-
Methods inherited from interface javax.persistence.EntityManagerFactory
addNamedEntityGraph, addNamedQuery, createEntityManager, createEntityManager, createEntityManager, createEntityManager, getCriteriaBuilder, getPersistenceUnitUtil, getProperties, isOpen, unwrap
-
Methods inherited from interface org.hibernate.jpa.HibernateEntityManagerFactory
findEntityGraphsByType, getEntityManagerFactoryName, getEntityTypeByName, getMetamodel, getSessionFactory
-
Methods inherited from interface javax.naming.Referenceable
getReference
-
-
-
-
Method Detail
-
getSessionFactoryOptions
SessionFactoryOptions getSessionFactoryOptions()
Get the special options used to build the factory.- Returns:
- The special options used to build the factory.
-
withOptions
SessionBuilder withOptions()
Obtain aSessionbuilder.- Returns:
- The session builder
-
openSession
Session openSession() throws HibernateException
Open aSession. JDBCconnection(swill be obtained from the configuredConnectionProvideras needed to perform requested work.- Returns:
- The created session.
- Throws:
HibernateException- Indicates a problem opening the session; pretty rare here.
-
getCurrentSession
Session getCurrentSession() throws HibernateException
Obtains the current session. The definition of what exactly "current" means controlled by theCurrentSessionContextimpl configured for use. Note that for backwards compatibility, if aCurrentSessionContextis not configured but JTA is configured this will default to theJTASessionContextimpl.- Returns:
- The current session.
- Throws:
HibernateException- Indicates an issue locating a suitable current session.
-
withStatelessOptions
StatelessSessionBuilder withStatelessOptions()
Obtain aStatelessSessionbuilder.- Returns:
- The stateless session builder
-
openStatelessSession
StatelessSession openStatelessSession()
Open a new stateless session.- Returns:
- The created stateless session.
-
openStatelessSession
StatelessSession openStatelessSession(Connection connection)
Open a new stateless session, utilizing the specified JDBCConnection.- Parameters:
connection- Connection provided by the application.- Returns:
- The created stateless session.
-
getStatistics
Statistics getStatistics()
Retrieve the statistics for this factory.- Returns:
- The statistics.
-
close
void close() throws HibernateExceptionDestroy this SessionFactory and release all resources (caches, connection pools, etc). It is the responsibility of the application to ensure that there are no opensessionsbefore calling this method as the impact on thosesessionsis indeterminate. No-ops if alreadyclosed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceEntityManagerFactory- Throws:
HibernateException- Indicates an issue closing the factory.
-
isClosed
boolean isClosed()
Is this factory already closed?- Returns:
- True if this factory is already closed; false otherwise.
-
getCache
Cache getCache()
Obtain direct access to the underlying cache regions.- Specified by:
getCachein interfaceEntityManagerFactory- Returns:
- The direct cache access API.
-
getDefinedFilterNames
Set getDefinedFilterNames()
Obtain a set of the names of all filters defined on this SessionFactory.- Returns:
- The set of filter names.
-
getFilterDefinition
FilterDefinition getFilterDefinition(String filterName) throws HibernateException
Obtain the definition of a filter by name.- 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
boolean containsFetchProfileDefinition(String name)
Determine if this session factory contains a fetch profile definition registered under the given name.- Parameters:
name- The name to check- Returns:
- True if there is such a fetch profile; false otherwise.
-
getTypeHelper
TypeHelper getTypeHelper()
Retrieve this factory'sTypeHelper.- Returns:
- The factory's
TypeHelper
-
getClassMetadata
@Deprecated ClassMetadata getClassMetadata(Class entityClass)
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadRetrieve theClassMetadataassociated with the given entity class.- Parameters:
entityClass- The entity class- Returns:
- The metadata associated with the given entity; may be null if no such entity was mapped.
- Throws:
HibernateException- Generally null is returned instead of throwing.
-
getClassMetadata
@Deprecated ClassMetadata getClassMetadata(String entityName)
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadRetrieve theClassMetadataassociated with the given entity class.- Parameters:
entityName- The entity class- Returns:
- The metadata associated with the given entity; may be null if no such entity was mapped.
- Throws:
HibernateException- Generally null is returned instead of throwing.- Since:
- 3.0
-
getCollectionMetadata
@Deprecated CollectionMetadata getCollectionMetadata(String roleName)
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadGet theCollectionMetadataassociated with the named collection role.- Parameters:
roleName- The collection role (in form [owning-entity-name].[collection-property-name]).- Returns:
- The metadata associated with the given collection; may be null if no such collection was mapped.
- Throws:
HibernateException- Generally null is returned instead of throwing.
-
getAllClassMetadata
@Deprecated Map<String,ClassMetadata> getAllClassMetadata()
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadRetrieve theClassMetadatafor all mapped entities.- Returns:
- A map containing all
ClassMetadatakeyed by the correspondingStringentity-name. - Throws:
HibernateException- Generally empty map is returned instead of throwing.- Since:
- 3.0 changed key from
ClasstoString.
-
getAllCollectionMetadata
@Deprecated Map getAllCollectionMetadata()
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()insteadGet theCollectionMetadatafor all mapped collections.- Returns:
- a map from String to CollectionMetadata
- Throws:
HibernateException- Generally empty map is returned instead of throwing.
-
-