程序包 org.hibernate
接口 SessionFactory
-
- 所有超级接口:
AutoCloseable,Closeable,javax.persistence.EntityManagerFactory,HibernateEntityManagerFactory,Referenceable,Serializable
- 所有已知子接口:
SessionFactoryImplementor
public interface SessionFactory extends javax.persistence.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.- 作者:
- Gavin King, Steve Ebersole
- 另请参阅:
Configuration
-
-
方法概要
所有方法 实例方法 抽象方法 已过时的方法 修饰符和类型 方法 说明 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()已过时。Use the descriptors fromEntityManagerFactory.getMetamodel()insteadMapgetAllCollectionMetadata()已过时。Use the descriptors fromEntityManagerFactory.getMetamodel()insteadCachegetCache()Obtain direct access to the underlying cache regions.ClassMetadatagetClassMetadata(Class entityClass)已过时。Use the descriptors fromEntityManagerFactory.getMetamodel()insteadClassMetadatagetClassMetadata(String entityName)已过时。Use the descriptors fromEntityManagerFactory.getMetamodel()insteadCollectionMetadatagetCollectionMetadata(String roleName)已过时。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.-
从接口继承的方法 javax.persistence.EntityManagerFactory
addNamedEntityGraph, addNamedQuery, createEntityManager, createEntityManager, createEntityManager, createEntityManager, getCriteriaBuilder, getPersistenceUnitUtil, getProperties, isOpen, unwrap
-
从接口继承的方法 org.hibernate.jpa.HibernateEntityManagerFactory
findEntityGraphsByType, getEntityManagerFactoryName, getEntityTypeByName, getMetamodel, getSessionFactory
-
从接口继承的方法 javax.naming.Referenceable
getReference
-
-
-
-
方法详细资料
-
getSessionFactoryOptions
SessionFactoryOptions getSessionFactoryOptions()
Get the special options used to build the factory.- 返回:
- The special options used to build the factory.
-
withOptions
SessionBuilder withOptions()
Obtain aSessionbuilder.- 返回:
- The session builder
-
openSession
Session openSession() throws HibernateException
Open aSession. JDBCconnection(swill be obtained from the configuredConnectionProvideras needed to perform requested work.- 返回:
- The created session.
- 抛出:
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.- 返回:
- The current session.
- 抛出:
HibernateException- Indicates an issue locating a suitable current session.
-
withStatelessOptions
StatelessSessionBuilder withStatelessOptions()
Obtain aStatelessSessionbuilder.- 返回:
- The stateless session builder
-
openStatelessSession
StatelessSession openStatelessSession()
Open a new stateless session.- 返回:
- The created stateless session.
-
openStatelessSession
StatelessSession openStatelessSession(Connection connection)
Open a new stateless session, utilizing the specified JDBCConnection.- 参数:
connection- Connection provided by the application.- 返回:
- The created stateless session.
-
getStatistics
Statistics getStatistics()
Retrieve the statistics for this factory.- 返回:
- 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.- 指定者:
close在接口中AutoCloseable- 指定者:
close在接口中Closeable- 指定者:
close在接口中javax.persistence.EntityManagerFactory- 抛出:
HibernateException- Indicates an issue closing the factory.
-
isClosed
boolean isClosed()
Is this factory already closed?- 返回:
- True if this factory is already closed; false otherwise.
-
getCache
Cache getCache()
Obtain direct access to the underlying cache regions.- 指定者:
getCache在接口中javax.persistence.EntityManagerFactory- 返回:
- The direct cache access API.
-
getDefinedFilterNames
Set getDefinedFilterNames()
Obtain a set of the names of all filters defined on this SessionFactory.- 返回:
- The set of filter names.
-
getFilterDefinition
FilterDefinition getFilterDefinition(String filterName) throws HibernateException
Obtain the definition of a filter by name.- 参数:
filterName- The name of the filter for which to obtain the definition.- 返回:
- The filter definition.
- 抛出:
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.- 参数:
name- The name to check- 返回:
- True if there is such a fetch profile; false otherwise.
-
getTypeHelper
TypeHelper getTypeHelper()
Retrieve this factory'sTypeHelper.- 返回:
- The factory's
TypeHelper
-
getClassMetadata
@Deprecated ClassMetadata getClassMetadata(Class entityClass)
已过时。Use the descriptors fromEntityManagerFactory.getMetamodel()insteadRetrieve theClassMetadataassociated with the given entity class.- 参数:
entityClass- The entity class- 返回:
- The metadata associated with the given entity; may be null if no such entity was mapped.
- 抛出:
HibernateException- Generally null is returned instead of throwing.
-
getClassMetadata
@Deprecated ClassMetadata getClassMetadata(String entityName)
已过时。Use the descriptors fromEntityManagerFactory.getMetamodel()insteadRetrieve theClassMetadataassociated with the given entity class.- 参数:
entityName- The entity class- 返回:
- The metadata associated with the given entity; may be null if no such entity was mapped.
- 抛出:
HibernateException- Generally null is returned instead of throwing.- 从以下版本开始:
- 3.0
-
getCollectionMetadata
@Deprecated CollectionMetadata getCollectionMetadata(String roleName)
已过时。Use the descriptors fromEntityManagerFactory.getMetamodel()insteadGet theCollectionMetadataassociated with the named collection role.- 参数:
roleName- The collection role (in form [owning-entity-name].[collection-property-name]).- 返回:
- The metadata associated with the given collection; may be null if no such collection was mapped.
- 抛出:
HibernateException- Generally null is returned instead of throwing.
-
getAllClassMetadata
@Deprecated Map<String,ClassMetadata> getAllClassMetadata()
已过时。Use the descriptors fromEntityManagerFactory.getMetamodel()insteadRetrieve theClassMetadatafor all mapped entities.- 返回:
- A map containing all
ClassMetadatakeyed by the correspondingStringentity-name. - 抛出:
HibernateException- Generally empty map is returned instead of throwing.- 从以下版本开始:
- 3.0 changed key from
ClasstoString.
-
getAllCollectionMetadata
@Deprecated Map getAllCollectionMetadata()
已过时。Use the descriptors fromEntityManagerFactory.getMetamodel()insteadGet theCollectionMetadatafor all mapped collections.- 返回:
- a map from String to CollectionMetadata
- 抛出:
HibernateException- Generally empty map is returned instead of throwing.
-
-