public interface

SessionFactory

implements Serializable Referenceable
org.hibernate.SessionFactory
Known Indirect Subclasses

Class Overview

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.

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.

Implementors must be threadsafe.

See Also

Summary

Public Methods
abstract void close()
Destroy this SessionFactory and release all resources (caches, connection pools, etc).
abstract boolean containsFetchProfileDefinition(String name)
Determine if this session factory contains a fetch profile definition registered under the given name.
abstract void evict(Class persistentClass, Serializable id)
This method is deprecated. Use containsEntity(Class, Serializable) accessed through getCache() instead.
abstract void evict(Class persistentClass)
This method is deprecated. Use evictEntityRegion(Class) accessed through getCache() instead.
abstract void evictCollection(String roleName, Serializable id)
This method is deprecated. Use evictCollection(String, Serializable) accessed through getCache() instead.
abstract void evictCollection(String roleName)
This method is deprecated. Use evictCollectionRegion(String) accessed through getCache() instead.
abstract void evictEntity(String entityName)
This method is deprecated. Use evictEntityRegion(String) accessed through getCache() instead.
abstract void evictEntity(String entityName, Serializable id)
This method is deprecated. Use evictEntity(String, Serializable) accessed through getCache() instead.
abstract void evictQueries()
This method is deprecated. Use evictQueryRegions() accessed through getCache() instead.
abstract void evictQueries(String cacheRegion)
This method is deprecated. Use evictQueryRegion(String) accessed through getCache() instead.
abstract Map<StringClassMetadata> getAllClassMetadata()
Retrieve the ClassMetadata for all mapped entities.
abstract Map getAllCollectionMetadata()
Get the CollectionMetadata for all mapped collections
abstract Cache getCache()
Obtain direct access to the underlying cache regions.
abstract ClassMetadata getClassMetadata(Class entityClass)
Retrieve the ClassMetadata associated with the given entity class.
abstract ClassMetadata getClassMetadata(String entityName)
Retrieve the ClassMetadata associated with the given entity class.
abstract CollectionMetadata getCollectionMetadata(String roleName)
Get the CollectionMetadata associated with the named collection role.
abstract Session getCurrentSession()
Obtains the current session.
abstract Set getDefinedFilterNames()
Obtain a set of the names of all filters defined on this SessionFactory.
abstract FilterDefinition getFilterDefinition(String filterName)
Obtain the definition of a filter by name.
abstract Statistics getStatistics()
Retrieve the statistics fopr this factory.
abstract TypeHelper getTypeHelper()
Retrieve this factory's TypeHelper
abstract boolean isClosed()
Is this factory already closed?
abstract Session openSession(Connection connection, Interceptor interceptor)
Open a Session, utilizing the specfied JDBC Connection and specified Interceptor.
abstract Session openSession()
Open a Session.
abstract Session openSession(Connection connection)
Open a Session, utilizing the specfied JDBC Connection.
abstract Session openSession(Interceptor interceptor)
Open a Session, utilizing the specified Interceptor.
abstract StatelessSession openStatelessSession(Connection connection)
Open a new stateless session, utilizing the specified JDBC Connection.
abstract StatelessSession openStatelessSession()
Open a new stateless session.
[Expand]
Inherited Methods
From interface javax.naming.Referenceable

Public Methods

public abstract void close ()

Destroy this SessionFactory and release all resources (caches, connection pools, etc).

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.

No-ops if already closed.

Throws
HibernateException Indicates an issue closing the factory.

public abstract 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.

public abstract void evict (Class persistentClass, Serializable id)

This method is deprecated.
Use containsEntity(Class, Serializable) accessed through getCache() instead.

Evict an entry from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Parameters
persistentClass The entity class for which to evict data.
id The entity id
Throws
HibernateException Generally will mean that either that 'persisttentClass' did not name a mapped entity or a problem communicating with underlying cache impl.

public abstract void evict (Class persistentClass)

This method is deprecated.
Use evictEntityRegion(Class) accessed through getCache() instead.

Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Parameters
persistentClass The entity class for which to evict data.
Throws
HibernateException Generally will mean that either that 'persisttentClass' did not name a mapped entity or a problem communicating with underlying cache impl.

public abstract void evictCollection (String roleName, Serializable id)

This method is deprecated.
Use evictCollection(String, Serializable) accessed through getCache() instead.

Evict an entry from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Parameters
roleName The name of the collection role
id The id of the collection owner
Throws
HibernateException Generally will mean that either that 'roleName' did not name a mapped collection or a problem communicating with underlying cache impl.

public abstract void evictCollection (String roleName)

This method is deprecated.
Use evictCollectionRegion(String) accessed through getCache() instead.

Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Parameters
roleName The name of the collection role whose regions should be evicted
Throws
HibernateException Generally will mean that either that 'roleName' did not name a mapped collection or a problem communicating with underlying cache impl.

public abstract void evictEntity (String entityName)

This method is deprecated.
Use evictEntityRegion(String) accessed through getCache() instead.

Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Parameters
entityName The entity name for which to evict data.
Throws
HibernateException Generally will mean that either that 'persisttentClass' did not name a mapped entity or a problem communicating with underlying cache impl.

public abstract void evictEntity (String entityName, Serializable id)

This method is deprecated.
Use evictEntity(String, Serializable) accessed through getCache() instead.

Evict an entry from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Parameters
entityName The entity name for which to evict data.
id The entity id
Throws
HibernateException Generally will mean that either that 'persisttentClass' did not name a mapped entity or a problem communicating with underlying cache impl.

public abstract void evictQueries ()

This method is deprecated.
Use evictQueryRegions() accessed through getCache() instead.

Evict any query result sets cached in the default query cache region.

Throws
HibernateException Indicate a problem communicating with underlying cache impl.

public abstract void evictQueries (String cacheRegion)

This method is deprecated.
Use evictQueryRegion(String) accessed through getCache() instead.

Evict any query result sets cached in the named query cache region.

Parameters
cacheRegion The named query cache region from which to evict.
Throws
HibernateException Since a not-found 'cacheRegion' simply no-ops, this should indicate a problem communicating with underlying cache impl.

public abstract Map<StringClassMetadata> getAllClassMetadata ()

Retrieve the ClassMetadata for all mapped entities.

Returns
Throws
HibernateException Generally empty map is returned instead of throwing.

public abstract Map getAllCollectionMetadata ()

Get the CollectionMetadata for all mapped collections

Returns
  • a map from String to CollectionMetadata
Throws
HibernateException Generally empty map is returned instead of throwing.

public abstract Cache getCache ()

Obtain direct access to the underlying cache regions.

Returns
  • The direct cache access API.

public abstract ClassMetadata getClassMetadata (Class entityClass)

Retrieve the ClassMetadata 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.

public abstract ClassMetadata getClassMetadata (String entityName)

Retrieve the ClassMetadata 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.

public abstract CollectionMetadata getCollectionMetadata (String roleName)

Get the CollectionMetadata 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.

public abstract Session getCurrentSession ()

Obtains the current session. The definition of what exactly "current" means controlled by the CurrentSessionContext impl configured for use.

Note that for backwards compatibility, if a CurrentSessionContext is not configured but a JTA TransactionManagerLookup is configured this will default to the JTASessionContext impl.

Returns
  • The current session.
Throws
HibernateException Indicates an issue locating a suitable current session.

public abstract Set getDefinedFilterNames ()

Obtain a set of the names of all filters defined on this SessionFactory.

Returns
  • The set of filter names.

public abstract FilterDefinition getFilterDefinition (String filterName)

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.

public abstract Statistics getStatistics ()

Retrieve the statistics fopr this factory.

Returns
  • The statistics.

public abstract TypeHelper getTypeHelper ()

Retrieve this factory's TypeHelper

Returns

public abstract boolean isClosed ()

Is this factory already closed?

Returns
  • True if this factory is already closed; false otherwise.

public abstract Session openSession (Connection connection, Interceptor interceptor)

Open a Session, utilizing the specfied JDBC Connection and specified Interceptor.

Note that the second-level cache will be disabled if you supply a JDBC connection. Hibernate will not be able to track any statements you might have executed in the same transaction. Consider implementing your own ConnectionProvider instead as a highly recommended alternative.

Parameters
connection a connection provided by the application.
interceptor a session-scoped interceptor
Returns
  • The created session.

public abstract Session openSession ()

Open a Session.

JDBC connection(s will be obtained from the configured ConnectionProvider as needed to perform requested work.

Returns
  • The created session.
Throws
HibernateException Indicates a peroblem opening the session; pretty rare here.

public abstract Session openSession (Connection connection)

Open a Session, utilizing the specfied JDBC Connection.

Note that the second-level cache will be disabled if you supply a JDBC connection. Hibernate will not be able to track any statements you might have executed in the same transaction. Consider implementing your own ConnectionProvider instead as a highly recommended alternative.

Parameters
connection a connection provided by the application.
Returns
  • The created session.

public abstract Session openSession (Interceptor interceptor)

Open a Session, utilizing the specified Interceptor.

JDBC connection(s will be obtained from the configured ConnectionProvider as needed to perform requested work.

Parameters
interceptor a session-scoped interceptor
Returns
  • The created session.
Throws
HibernateException Indicates a peroblem opening the session; pretty rare here.

public abstract StatelessSession openStatelessSession (Connection connection)

Open a new stateless session, utilizing the specified JDBC Connection.

Parameters
connection Connection provided by the application.
Returns
  • The created stateless session.

public abstract StatelessSession openStatelessSession ()

Open a new stateless session.

Returns
  • The created stateless session.