Package org.hibernate
Interface SessionFactory
- All Superinterfaces:
Referenceable,Serializable
- All Known Subinterfaces:
SessionFactoryImplementor
- All Known Implementing Classes:
SessionFactoryImpl,SessionFactoryStub
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:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Destroy this SessionFactory and release all resources (caches, connection pools, etc).booleanDetermine if this session factory contains a fetch profile definition registered under the given name.voidDeprecated.voidevict(Class persistentClass, Serializable id) Deprecated.UseCache.containsEntity(Class, Serializable)accessed throughgetCache()instead.voidevictCollection(String roleName) Deprecated.UseCache.evictCollectionRegion(String)accessed throughgetCache()instead.voidevictCollection(String roleName, Serializable id) Deprecated.UseCache.evictCollection(String,Serializable)accessed throughgetCache()instead.voidevictEntity(String entityName) Deprecated.UseCache.evictEntityRegion(String)accessed throughgetCache()instead.voidevictEntity(String entityName, Serializable id) Deprecated.UseCache.evictEntity(String,Serializable)accessed throughgetCache()instead.voidDeprecated.UseCache.evictQueryRegions()accessed throughgetCache()instead.voidevictQueries(String cacheRegion) Deprecated.UseCache.evictQueryRegion(String)accessed throughgetCache()instead.Retrieve theClassMetadatafor all mapped entities.Get theCollectionMetadatafor all mapped collectionsgetCache()Obtain direct access to the underlying cache regions.getClassMetadata(Class entityClass) Retrieve theClassMetadataassociated with the given entity class.getClassMetadata(String entityName) Retrieve theClassMetadataassociated with the given entity class.getCollectionMetadata(String roleName) Get theCollectionMetadataassociated with the named collection role.Obtains the current session.Obtain a set of the names of all filters defined on this SessionFactory.getFilterDefinition(String filterName) Obtain the definition of a filter by name.Retrieve the statistics fopr this factory.Retrieve this factory'sTypeHelperbooleanisClosed()Is this factory already closed?Open aSession.openSession(Connection connection) Open aSession, utilizing the specfied JDBCConnection.openSession(Connection connection, Interceptor interceptor) openSession(Interceptor interceptor) Open aSession, utilizing the specifiedInterceptor.Open a new stateless session.openStatelessSession(Connection connection) Open a new stateless session, utilizing the specified JDBCConnection.Methods inherited from interface javax.naming.Referenceable
getReference
-
Method Details
-
openSession
Open aSession. JDBCconnection(swill be obtained from the configuredConnectionProvideras needed to perform requested work.- Returns:
- The created session.
- Throws:
HibernateException- Indicates a peroblem opening the session; pretty rare here.
-
openSession
Open aSession, utilizing the specifiedInterceptor. JDBCconnection(swill be obtained from the configuredConnectionProvideras 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.
-
openSession
Open aSession, utilizing the specfied JDBCConnection.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
ConnectionProviderinstead as a highly recommended alternative.- Parameters:
connection- a connection provided by the application.- Returns:
- The created session.
-
openSession
Open aSession, utilizing the specfied JDBCConnectionand specifiedInterceptor.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
ConnectionProviderinstead as a highly recommended alternative.- Parameters:
connection- a connection provided by the application.interceptor- a session-scoped interceptor- Returns:
- The created session.
-
getCurrentSession
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 a JTATransactionManagerLookupis configured this will default to theJTASessionContextimpl.- Returns:
- The current session.
- Throws:
HibernateException- Indicates an issue locating a suitable current session.
-
openStatelessSession
StatelessSession openStatelessSession()Open a new stateless session.- Returns:
- The created stateless session.
-
openStatelessSession
Open a new stateless session, utilizing the specified JDBCConnection.- Parameters:
connection- Connection provided by the application.- Returns:
- The created stateless session.
-
getClassMetadata
Retrieve theClassMetadataassociated 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
Retrieve theClassMetadataassociated 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
Get theCollectionMetadataassociated 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
Map<String,ClassMetadata> getAllClassMetadata()Retrieve theClassMetadatafor all mapped entities.- Returns:
- A map containing all
ClassMetadatakeyed by the correspondingStringentity-name. - Throws:
HibernateException- Generally empty map is returned instead of throwing.- Since:
- 3.0 changed key from
ClasstoString.
-
getAllCollectionMetadata
Map getAllCollectionMetadata()Get theCollectionMetadatafor all mapped collections- Returns:
- a map from String to CollectionMetadata
- Throws:
HibernateException- Generally empty map is returned instead of throwing.
-
getStatistics
Statistics getStatistics()Retrieve the statistics fopr this factory.- Returns:
- The statistics.
-
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 opensessionsbefore calling this method as the impact on thosesessionsis indeterminate. No-ops if alreadyclosed.- 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.- Returns:
- The direct cache access API.
-
evict
Deprecated.UseCache.evictEntityRegion(Class)accessed throughgetCache()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.
-
evict
Deprecated.UseCache.containsEntity(Class, Serializable)accessed throughgetCache()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.
-
evictEntity
Deprecated.UseCache.evictEntityRegion(String)accessed throughgetCache()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.
-
evictEntity
Deprecated.UseCache.evictEntity(String,Serializable)accessed throughgetCache()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.
-
evictCollection
Deprecated.UseCache.evictCollectionRegion(String)accessed throughgetCache()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.
-
evictCollection
Deprecated.UseCache.evictCollection(String,Serializable)accessed throughgetCache()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 roleid- 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.
-
evictQueries
Deprecated.UseCache.evictQueryRegion(String)accessed throughgetCache()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.
-
evictQueries
Deprecated.UseCache.evictQueryRegions()accessed throughgetCache()instead.Evict any query result sets cached in the default query cache region.- Throws:
HibernateException- Indicate a problem communicating with underlying cache impl.
-
getDefinedFilterNames
Set getDefinedFilterNames()Obtain a set of the names of all filters defined on this SessionFactory.- Returns:
- The set of filter names.
-
getFilterDefinition
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
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
-
Cache.evictEntityRegion(Class)accessed throughgetCache()instead.