Package org.hibernate
Interface SessionFactory
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
,EntityManagerFactory
,HibernateEntityManagerFactory
,javax.naming.Referenceable
,java.io.Serializable
- All Known Subinterfaces:
SessionFactoryImplementor
- All Known Implementing Classes:
SessionFactoryDelegatingImpl
public interface SessionFactory extends EntityManagerFactory, HibernateEntityManagerFactory, javax.naming.Referenceable, java.io.Serializable, java.io.Closeable
The main contract here is the creation ofSession
instances. Usually an application has a singleSessionFactory
instance and threads servicing client requests obtainSession
instances from this factory. The internal state of aSessionFactory
is 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 void
close()
Destroy this SessionFactory and release all resources (caches, connection pools, etc).boolean
containsFetchProfileDefinition(java.lang.String name)
Determine if this session factory contains a fetch profile definition registered under the given name.java.util.Map<java.lang.String,ClassMetadata>
getAllClassMetadata()
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadjava.util.Map
getAllCollectionMetadata()
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadCache
getCache()
Obtain direct access to the underlying cache regions.ClassMetadata
getClassMetadata(java.lang.Class entityClass)
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadClassMetadata
getClassMetadata(java.lang.String entityName)
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadCollectionMetadata
getCollectionMetadata(java.lang.String roleName)
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadSession
getCurrentSession()
Obtains the current session.java.util.Set
getDefinedFilterNames()
Obtain a set of the names of all filters defined on this SessionFactory.FilterDefinition
getFilterDefinition(java.lang.String filterName)
Obtain the definition of a filter by name.SessionFactoryOptions
getSessionFactoryOptions()
Get the special options used to build the factory.Statistics
getStatistics()
Retrieve the statistics fopr this factory.TypeHelper
getTypeHelper()
Retrieve this factory'sTypeHelper
.boolean
isClosed()
Is this factory already closed?Session
openSession()
Open aSession
.StatelessSession
openStatelessSession()
Open a new stateless session.StatelessSession
openStatelessSession(java.sql.Connection connection)
Open a new stateless session, utilizing the specified JDBCConnection
.SessionBuilder
withOptions()
Obtain aSession
builder.StatelessSessionBuilder
withStatelessOptions()
Obtain aStatelessSession
builder.-
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
-
-
-
-
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 aSession
builder.- Returns:
- The session builder
-
openSession
Session openSession() throws HibernateException
Open aSession
. JDBCconnection(s
will be obtained from the configuredConnectionProvider
as 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 theCurrentSessionContext
impl configured for use. Note that for backwards compatibility, if aCurrentSessionContext
is not configured but JTA is configured this will default to theJTASessionContext
impl.- Returns:
- The current session.
- Throws:
HibernateException
- Indicates an issue locating a suitable current session.
-
withStatelessOptions
StatelessSessionBuilder withStatelessOptions()
Obtain aStatelessSession
builder.- Returns:
- The stateless session builder
-
openStatelessSession
StatelessSession openStatelessSession()
Open a new stateless session.- Returns:
- The created stateless session.
-
openStatelessSession
StatelessSession openStatelessSession(java.sql.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 fopr this factory.- Returns:
- The statistics.
-
close
void close() throws HibernateException
Destroy this SessionFactory and release all resources (caches, connection pools, etc). It is the responsibility of the application to ensure that there are no opensessions
before calling this method as the impact on thosesessions
is indeterminate. No-ops if alreadyclosed
.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in 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:
getCache
in interfaceEntityManagerFactory
- Returns:
- The direct cache access API.
-
getDefinedFilterNames
java.util.Set getDefinedFilterNames()
Obtain a set of the names of all filters defined on this SessionFactory.- Returns:
- The set of filter names.
-
getFilterDefinition
FilterDefinition getFilterDefinition(java.lang.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(java.lang.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(java.lang.Class entityClass)
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadRetrieve theClassMetadata
associated 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(java.lang.String entityName)
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadRetrieve theClassMetadata
associated 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(java.lang.String roleName)
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadGet theCollectionMetadata
associated 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 java.util.Map<java.lang.String,ClassMetadata> getAllClassMetadata()
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadRetrieve theClassMetadata
for all mapped entities.- Returns:
- A map containing all
ClassMetadata
keyed by the correspondingString
entity-name. - Throws:
HibernateException
- Generally empty map is returned instead of throwing.- Since:
- 3.0 changed key from
Class
toString
.
-
getAllCollectionMetadata
@Deprecated java.util.Map getAllCollectionMetadata()
Deprecated.Use the descriptors fromEntityManagerFactory.getMetamodel()
insteadGet theCollectionMetadata
for all mapped collections.- Returns:
- a map from String to CollectionMetadata
- Throws:
HibernateException
- Generally empty map is returned instead of throwing.
-
-