public interface SessionFactory extends EntityManagerFactory, HibernateEntityManagerFactory, Referenceable, Serializable, Closeable
The main contract here is the creation of Session
instances. Usually
an application has a single SessionFactory
instance and threads
servicing client requests obtain Session
instances from this factory.
<p/>
The internal state of a SessionFactory
is immutable. Once it is created
this internal state is set. This internal state includes all of the metadata
about Object/Relational Mapping.
<p/>
Implementors <strong>must</strong> be threadsafe.
Configuration
Modifier and Type | Method and Description |
---|---|
void |
close()
Destroy this <tt>SessionFactory</tt> and release all resources (caches,
connection pools, etc).
|
boolean |
containsFetchProfileDefinition(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 from
EntityManagerFactory.getMetamodel() instead |
Map |
getAllCollectionMetadata()
Deprecated.
Use the descriptors from
EntityManagerFactory.getMetamodel() instead |
Cache |
getCache()
Obtain direct access to the underlying cache regions.
|
ClassMetadata |
getClassMetadata(Class entityClass)
Deprecated.
Use the descriptors from
EntityManagerFactory.getMetamodel() instead |
ClassMetadata |
getClassMetadata(String entityName)
Deprecated.
Use the descriptors from
EntityManagerFactory.getMetamodel() instead |
CollectionMetadata |
getCollectionMetadata(String roleName)
Deprecated.
Use the descriptors from
EntityManagerFactory.getMetamodel() instead |
Session |
getCurrentSession()
Obtains the current session.
|
Set |
getDefinedFilterNames()
Obtain a set of the names of all filters defined on this SessionFactory.
|
FilterDefinition |
getFilterDefinition(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’s
TypeHelper . |
boolean |
isClosed()
Is this factory already closed?
|
Session |
openSession()
Open a
Session . |
StatelessSession |
openStatelessSession()
Open a new stateless session.
|
StatelessSession |
openStatelessSession(Connection connection)
Open a new stateless session, utilizing the specified JDBC
Connection . |
SessionBuilder |
withOptions()
Obtain a
Session builder. |
StatelessSessionBuilder |
withStatelessOptions()
Obtain a
StatelessSession builder. |
findEntityGraphsByType, getEntityManagerFactoryName, getEntityTypeByName, getMetamodel, getSessionFactory
addNamedEntityGraph, addNamedQuery, createEntityManager, createEntityManager, createEntityManager, createEntityManager, getCriteriaBuilder, getPersistenceUnitUtil, getProperties, isOpen, unwrap
getReference
SessionFactoryOptions getSessionFactoryOptions()
Get the special options used to build the factory.
SessionBuilder withOptions()
Obtain a Session
builder.
Session openSession() throws HibernateException
Open a Session
.
<p/>
JDBC connection(s
will be obtained from the
configured ConnectionProvider
as needed
to perform requested work.
HibernateException
- Indicates a problem opening the session; pretty rare here.Session getCurrentSession() throws HibernateException
Obtains the current session. The definition of what exactly "current"
means controlled by the CurrentSessionContext
impl configured
for use.
<p/>
Note that for backwards compatibility, if a CurrentSessionContext
is not configured but JTA is configured this will default to the org.hibernate.context.internal.JTASessionContext
impl.
HibernateException
- Indicates an issue locating a suitable current session.StatelessSessionBuilder withStatelessOptions()
Obtain a StatelessSession
builder.
StatelessSession openStatelessSession()
Open a new stateless session.
StatelessSession openStatelessSession(Connection connection)
Open a new stateless session, utilizing the specified JDBC
Connection
.
connection
- Connection provided by the application.Statistics getStatistics()
Retrieve the statistics fopr this factory.
void close() throws HibernateException
Destroy this <tt>SessionFactory</tt> and release all resources (caches,
connection pools, etc).
<p/>
It is the responsibility of the application to ensure that there are no
open sessions
before calling this method as the impact
on those sessions
is indeterminate.
<p/>
No-ops if already closed
.
close
in interface AutoCloseable
close
in interface Closeable
close
in interface EntityManagerFactory
HibernateException
- Indicates an issue closing the factory.boolean isClosed()
Is this factory already closed?
Cache getCache()
Obtain direct access to the underlying cache regions.
getCache
in interface EntityManagerFactory
Set getDefinedFilterNames()
Obtain a set of the names of all filters defined on this SessionFactory.
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.HibernateException
- If no filter defined with the given name.boolean containsFetchProfileDefinition(String name)
Determine if this session factory contains a fetch profile definition registered under the given name.
name
- The name to checkTypeHelper getTypeHelper()
Retrieve this factory’s TypeHelper
.
TypeHelper
@Deprecated ClassMetadata getClassMetadata(Class entityClass)
EntityManagerFactory.getMetamodel()
insteadRetrieve the ClassMetadata
associated with the given entity class.
entityClass
- The entity classHibernateException
- Generally null is returned instead of throwing.@Deprecated ClassMetadata getClassMetadata(String entityName)
EntityManagerFactory.getMetamodel()
insteadRetrieve the ClassMetadata
associated with the given entity class.
entityName
- The entity classHibernateException
- Generally null is returned instead of throwing.@Deprecated CollectionMetadata getCollectionMetadata(String roleName)
EntityManagerFactory.getMetamodel()
insteadGet the CollectionMetadata
associated with the named collection role.
roleName
- The collection role (in form [owning-entity-name].[collection-property-name]).HibernateException
- Generally null is returned instead of throwing.@Deprecated Map<String,ClassMetadata> getAllClassMetadata()
EntityManagerFactory.getMetamodel()
insteadRetrieve the ClassMetadata
for all mapped entities.
ClassMetadata
keyed by the
corresponding String
entity-name.HibernateException
- Generally empty map is returned instead of throwing.Class
to String
.@Deprecated Map getAllCollectionMetadata()
EntityManagerFactory.getMetamodel()
insteadGet the CollectionMetadata
for all mapped collections.
HibernateException
- Generally empty map is returned instead of throwing.Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.