Top Description Methods
org.hibernate

public Interface SessionFactory

extends EntityManagerFactory, HibernateEntityManagerFactory, Referenceable, Serializable, Closeable
Known Direct Subinterfaces
org.hibernate.engine.spi.SessionFactoryImplementor
Known Direct Implementers
org.hibernate.engine.spi.SessionFactoryDelegatingImpl
Imports
java.io.Serializable, java.sql.Connection, java.util.Map, .Set, javax.naming.Referenceable, javax.persistence.EntityManagerFactory, org.hibernate.boot.spi.SessionFactoryOptions, org.hibernate.engine.spi.FilterDefinition, org.hibernate.jpa.HibernateEntityManagerFactory, org.hibernate.metadata.ClassMetadata, .CollectionMetadata, org.hibernate.stat.Statistics

Deprecated

as a consequence of HibernateEntityManagerFactory being deprecated. See corresponding docs for further information.

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.

Authors
Gavin King, Steve Ebersole
See Also
org.hibernate.cfg.Configuration

Method Summary

Modifier and TypeMethod and Description
public void
close()

Redeclares javax.persistence.EntityManagerFactory.close, java.io.Closeable.close.

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

Returns:

True if there is such a fetch profile; false otherwise.
containsFetchProfileDefinition
(String
The name to check
name
)

Determine if this session factory contains a fetch profile definition registered under the given name.

public Map<String, ClassMetadata>

Returns:

A map containing all ClassMetadata keyed by the corresponding String entity-name.
getAllClassMetadata
()

Deprecated Use the descriptors from getMetamodel() instead
Retrieve the ClassMetadata for all mapped entities.
public Map<K, V>

Returns:

a map from String to CollectionMetadata
getAllCollectionMetadata
()

Deprecated Use the descriptors from getMetamodel() instead
Get the CollectionMetadata for all mapped collections.
public Cache

Returns:

The direct cache access API.
getCache
()

Redeclares javax.persistence.EntityManagerFactory.getCache.

Obtain direct access to the underlying cache regions.
public ClassMetadata

Returns:

The metadata associated with the given entity; may be null if no such entity was mapped.
getClassMetadata
(Class<T>
The entity class
entityClass
)

Deprecated Use the descriptors from getMetamodel() instead
Retrieve the ClassMetadata associated with the given entity class.
public ClassMetadata

Returns:

The metadata associated with the given entity; may be null if no such entity was mapped.
getClassMetadata
(String
The entity class
entityName
)

Deprecated Use the descriptors from getMetamodel() instead
Retrieve the ClassMetadata associated with the given entity class.
public CollectionMetadata

Returns:

The metadata associated with the given collection; may be null if no such collection was mapped.
getCollectionMetadata
(String
The collection role (in form [owning-entity-name].[collection-property-name]).
roleName
)

Deprecated Use the descriptors from getMetamodel() instead
Get the CollectionMetadata associated with the named collection role.
public Session

Returns:

The current session.
getCurrentSession
()

Deprecated as a consequence of Session being deprecated.
Obtains the current session.
public Set<E>

Returns:

The set of filter names.
getDefinedFilterNames
()

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

public FilterDefinition

Returns:

The filter definition.
getFilterDefinition
(String
The name of the filter for which to obtain the definition.
filterName
)

Obtain the definition of a filter by name.

public SessionFactoryOptions

Returns:

The special options used to build the factory.
getSessionFactoryOptions
()

Get the special options used to build the factory.

public Statistics

Returns:

The statistics.
getStatistics
()

Retrieve the statistics for this factory.

public TypeHelper

Returns:

The factory's TypeHelper
getTypeHelper
()

Retrieve this factory's TypeHelper.

public boolean

Returns:

True if this factory is already closed; false otherwise.
isClosed
()

Is this factory already closed?

public Session

Returns:

The created session.
openSession
()

Deprecated as a consequence of Session being deprecated.
Open a Session.
public StatelessSession

Returns:

The created stateless session.
openStatelessSession
()

Open a new stateless session.

public StatelessSession

Returns:

The created stateless session.
openStatelessSession
(Connection
Connection provided by the application.
connection
)

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

public SessionBuilder<T extends SessionBuilder>

Returns:

The session builder
withOptions
()

Obtain a Session builder.

public StatelessSessionBuilder<T extends StatelessSessionBuilder>

Returns:

The stateless session builder
withStatelessOptions
()

Obtain a StatelessSession builder.

Inherited from javax.naming.Referenceable:
getReference
Inherited from javax.persistence.EntityManagerFactory:
addNamedEntityGraphaddNamedQuerycreateEntityManagercreateEntityManagercreateEntityManagercreateEntityManagergetCriteriaBuildergetMetamodelgetPersistenceUnitUtilgetPropertiesisOpenunwrap
Inherited from org.hibernate.jpa.HibernateEntityManagerFactory:
findEntityGraphsByTypegetEntityManagerFactoryNamegetEntityTypeByNamegetMetamodelgetSessionFactory

Method Detail

closeback to summary
public void close() throws HibernateException

Redeclares javax.persistence.EntityManagerFactory.close, java.io.Closeable.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.

Exceptions
HibernateException:
Indicates an issue closing the factory.
containsFetchProfileDefinitionback to summary
public boolean containsFetchProfileDefinition(String name)

Determine if this session factory contains a fetch profile definition registered under the given name.

Parameters
name:String

The name to check

Returns:boolean

True if there is such a fetch profile; false otherwise.

getAllClassMetadataback to summary
public Map<String, ClassMetadata> getAllClassMetadata()

Deprecated

Use the descriptors from getMetamodel() instead

Retrieve the ClassMetadata for all mapped entities.

Returns:Map<String, ClassMetadata>

A map containing all ClassMetadata keyed by the corresponding String entity-name.

Annotations
@Deprecated
Exceptions
HibernateException:
Generally empty map is returned instead of throwing.
Since
3.0 changed key from Class to String.
getAllCollectionMetadataback to summary
public Map<K, V> getAllCollectionMetadata()

Deprecated

Use the descriptors from getMetamodel() instead

Get the CollectionMetadata for all mapped collections.

Returns:Map<K, V>

a map from String to CollectionMetadata

Annotations
@Deprecated
Exceptions
HibernateException:
Generally empty map is returned instead of throwing.
getCacheback to summary
public Cache getCache()

Redeclares javax.persistence.EntityManagerFactory.getCache.

Obtain direct access to the underlying cache regions.

Returns:Cache

The direct cache access API.

Annotations
@Override
getClassMetadataback to summary
public ClassMetadata getClassMetadata(Class<T> entityClass)

Deprecated

Use the descriptors from getMetamodel() instead

Retrieve the ClassMetadata associated with the given entity class.

Parameters
entityClass:Class<T>

The entity class

Returns:ClassMetadata

The metadata associated with the given entity; may be null if no such entity was mapped.

Annotations
@Deprecated
Exceptions
HibernateException:
Generally null is returned instead of throwing.
getClassMetadataback to summary
public ClassMetadata getClassMetadata(String entityName)

Deprecated

Use the descriptors from getMetamodel() instead

Retrieve the ClassMetadata associated with the given entity class.

Parameters
entityName:String

The entity class

Returns:ClassMetadata

The metadata associated with the given entity; may be null if no such entity was mapped.

Annotations
@Deprecated
Exceptions
HibernateException:
Generally null is returned instead of throwing.
Since
3.0
getCollectionMetadataback to summary
public CollectionMetadata getCollectionMetadata(String roleName)

Deprecated

Use the descriptors from getMetamodel() instead

Get the CollectionMetadata associated with the named collection role.

Parameters
roleName:String

The collection role (in form [owning-entity-name].[collection-property-name]).

Returns:CollectionMetadata

The metadata associated with the given collection; may be null if no such collection was mapped.

Annotations
@Deprecated
Exceptions
HibernateException:
Generally null is returned instead of throwing.
getCurrentSessionback to summary
public Session getCurrentSession() throws HibernateException

Deprecated

as a consequence of Session being deprecated. See corresponding docs for further information.

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

Note that for backwards compatibility, if a org.hibernate.context.spi.CurrentSessionContext is not configured but JTA is configured this will default to the org.hibernate.context.internal.JTASessionContext impl.

Returns:Session

The current session.

Exceptions
HibernateException:
Indicates an issue locating a suitable current session.
getDefinedFilterNamesback to summary
public Set<E> getDefinedFilterNames()

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

Returns:Set<E>

The set of filter names.

getFilterDefinitionback to summary
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException

Obtain the definition of a filter by name.

Parameters
filterName:String

The name of the filter for which to obtain the definition.

Returns:FilterDefinition

The filter definition.

Exceptions
HibernateException:
If no filter defined with the given name.
getSessionFactoryOptionsback to summary
public SessionFactoryOptions getSessionFactoryOptions()

Get the special options used to build the factory.

Returns:SessionFactoryOptions

The special options used to build the factory.

getStatisticsback to summary
public Statistics getStatistics()

Retrieve the statistics for this factory.

Returns:Statistics

The statistics.

getTypeHelperback to summary
public TypeHelper getTypeHelper()

Retrieve this factory's TypeHelper.

Returns:TypeHelper

The factory's TypeHelper

isClosedback to summary
public boolean isClosed()

Is this factory already closed?

Returns:boolean

True if this factory is already closed; false otherwise.

openSessionback to summary
public Session openSession() throws HibernateException

Deprecated

as a consequence of Session being deprecated. See corresponding docs for further information.

Open a Session.

JDBC connection(s will be obtained from the configured org.hibernate.engine.jdbc.connections.spi.ConnectionProvider as needed to perform requested work.

Returns:Session

The created session.

Exceptions
HibernateException:
Indicates a problem opening the session; pretty rare here.
openStatelessSessionback to summary
public StatelessSession openStatelessSession()

Open a new stateless session.

Returns:StatelessSession

The created stateless session.

openStatelessSessionback to summary
public StatelessSession openStatelessSession(Connection connection)

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

Parameters
connection:Connection

Connection provided by the application.

Returns:StatelessSession

The created stateless session.

withOptionsback to summary
public SessionBuilder<T extends SessionBuilder> withOptions()

Obtain a Session builder.

Returns:SessionBuilder<T extends SessionBuilder>

The session builder

withStatelessOptionsback to summary
public StatelessSessionBuilder<T extends StatelessSessionBuilder> withStatelessOptions()

Obtain a StatelessSession builder.

Returns:StatelessSessionBuilder<T extends StatelessSessionBuilder>

The stateless session builder