Package org.hibernate.impl
Class SessionFactoryImpl
java.lang.Object
org.hibernate.impl.SessionFactoryImpl
- All Implemented Interfaces:
Serializable,Referenceable,Mapping,SessionFactoryImplementor,SessionFactory
public final class SessionFactoryImpl
extends Object
implements SessionFactory, SessionFactoryImplementor
Concrete implementation of the SessionFactory interface. Has the following
responsibilities
- caches configuration settings (immutably)
- caches "compiled" mappings ie. EntityPersisters and CollectionPersisters (immutable)
- caches "compiled" queries (memory sensitive cache)
- manages PreparedStatements
- delegates JDBC Connection management to the ConnectionProvider
- factory for instances of SessionImpl
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSessionFactoryImpl(Configuration cfg, Mapping mapping, Settings settings, EventListeners listeners, SessionFactoryObserver observer) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the session factory, releasing all held resources.booleanDetermine if this session factory contains a fetch profile definition registered under the given name.voidEvict all entries from the second-level cache.voidevict(Class persistentClass, Serializable id) Evict an entry from the second-level cache.voidevictCollection(String roleName) Evict all entries from the second-level cache.voidevictCollection(String roleName, Serializable id) Evict an entry from the second-level cache.voidevictEntity(String entityName) Evict all entries from the second-level cache.voidevictEntity(String entityName, Serializable id) Evict an entry from the second-level cache.voidEvict any query result sets cached in the default query cache region.voidevictQueries(String regionName) Evict any query result sets cached in the named query cache region.Retrieve theClassMetadatafor all mapped entities.Get theCollectionMetadatafor all mapped collectionsGet a map of all the second level cache regions currently maintained in this session factory.getCache()Obtain direct access to the underlying cache regions.getClassMetadata(Class persistentClass) 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.getCollectionPersister(String role) Get the persister object for a collection role.getCollectionRolesByEntityParticipant(String entityName) Retrieves a set of all the collection roles in which the given entity is a participant, as either an index or an element.Get the connection providerObtains the current session.Obtain a set of the names of all filters defined on this SessionFactory.Get the SQL dialect.getEntityPersister(String entityName) Get the persister for the named entityReturn the SessionFactoryObserver attached to the SessionFactory if anygetFetchProfile(String name) Retrieve fetch profile by name.getFilterDefinition(String filterName) Obtain the definition of a filter by name.getIdentifierGenerator(String rootEntityName) Get the identifier generator for the hierarchyAllow access to the id generator factory, though this is only needed/allowed from configuration.getIdentifierPropertyName(String className) getIdentifierType(String className) String[]getImplementors(String className) Return the names of all persistent (mapped) classes that extend or implement the given class or interface, accounting for implicit/explicit polymorphism settings and excluding mapped subclasses/joined-subclasses of other classes in the result.getImportedClassName(String className) Get a class name, using query language importsGet the factory scoped interceptor for this factory.getNamedQuery(String queryName) getNamedSQLQuery(String queryName) Get a copy of the Properties used to configure this session factory.Get the default query cachegetQueryCache(String regionName) Get a particular named query cache, or the default cachegetReferencedPropertyType(String className, String propertyName) getResultSetMapping(String resultSetName) String[]getReturnAliases(String queryString) Get the return aliases of a queryType[]getReturnTypes(String queryString) Get the return types of a querygetSecondLevelCacheRegion(String regionName) Get a named second-level cache regionRetrieves the SQLExceptionConverter in effect for this SessionFactory.Retrieve the statistics fopr this factory.Statistics SPIGet the JTA transaction managerRetrieve this factory'sTypeHelperRetrieve theTyperesolver associated with this factory.Get the cache of table update timestampsbooleanisClosed()Is this factory already closed?iterateEntityNameResolvers(EntityMode entityMode) Open aSession.openSession(Connection connection) Open aSession, utilizing the specfied JDBCConnection.openSession(Connection connection, boolean flushBeforeCompletionEnabled, boolean autoCloseSessionEnabled, ConnectionReleaseMode connectionReleaseMode) Open a session conforming to the given parameters.openSession(Connection connection, Interceptor sessionLocalInterceptor) openSession(Interceptor sessionLocalInterceptor) Open aSession, utilizing the specifiedInterceptor.Open a new stateless session.openStatelessSession(Connection connection) Open a new stateless session, utilizing the specified JDBCConnection.Get a nontransactional "current" session for Hibernate EntityManagervoidregisterEntityNameResolver(EntityNameResolver resolver, EntityMode entityMode)
-
Constructor Details
-
SessionFactoryImpl
public SessionFactoryImpl(Configuration cfg, Mapping mapping, Settings settings, EventListeners listeners, SessionFactoryObserver observer) throws HibernateException - Throws:
HibernateException
-
-
Method Details
-
getProperties
Description copied from interface:SessionFactoryImplementorGet a copy of the Properties used to configure this session factory.- Specified by:
getPropertiesin interfaceSessionFactoryImplementor- Returns:
- The properties.
-
getIdentifierGeneratorFactory
Description copied from interface:MappingAllow access to the id generator factory, though this is only needed/allowed from configuration.- Specified by:
getIdentifierGeneratorFactoryin interfaceMapping- Returns:
-
getTypeResolver
Description copied from interface:SessionFactoryImplementorRetrieve theTyperesolver associated with this factory.- Specified by:
getTypeResolverin interfaceSessionFactoryImplementor- Returns:
- The type resolver
-
registerEntityNameResolver
-
iterateEntityNameResolvers
-
getQueryPlanCache
- Specified by:
getQueryPlanCachein interfaceSessionFactoryImplementor
-
openStatelessSession
Description copied from interface:SessionFactoryOpen a new stateless session.- Specified by:
openStatelessSessionin interfaceSessionFactory- Returns:
- The created stateless session.
-
openStatelessSession
Description copied from interface:SessionFactoryOpen a new stateless session, utilizing the specified JDBCConnection.- Specified by:
openStatelessSessionin interfaceSessionFactory- Parameters:
connection- Connection provided by the application.- Returns:
- The created stateless session.
-
openSession
Description copied from interface:SessionFactoryOpen 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.- Specified by:
openSessionin interfaceSessionFactory- Parameters:
connection- a connection provided by the application.sessionLocalInterceptor- a session-scoped interceptor- Returns:
- The created session.
-
openSession
Description copied from interface:SessionFactoryOpen aSession, utilizing the specifiedInterceptor. JDBCconnection(swill be obtained from the configuredConnectionProvideras needed to perform requested work.- Specified by:
openSessionin interfaceSessionFactory- Parameters:
sessionLocalInterceptor- a session-scoped interceptor- Returns:
- The created session.
- Throws:
HibernateException- Indicates a peroblem opening the session; pretty rare here.
-
openSession
Description copied from interface:SessionFactoryOpen 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.- Specified by:
openSessionin interfaceSessionFactory- Parameters:
connection- a connection provided by the application.- Returns:
- The created session.
-
openSession
Description copied from interface:SessionFactoryOpen aSession. JDBCconnection(swill be obtained from the configuredConnectionProvideras needed to perform requested work.- Specified by:
openSessionin interfaceSessionFactory- Returns:
- The created session.
- Throws:
HibernateException- Indicates a peroblem opening the session; pretty rare here.
-
openTemporarySession
Description copied from interface:SessionFactoryImplementorGet a nontransactional "current" session for Hibernate EntityManager- Specified by:
openTemporarySessionin interfaceSessionFactoryImplementor- Throws:
HibernateException
-
openSession
public Session openSession(Connection connection, boolean flushBeforeCompletionEnabled, boolean autoCloseSessionEnabled, ConnectionReleaseMode connectionReleaseMode) throws HibernateException Description copied from interface:SessionFactoryImplementorOpen a session conforming to the given parameters. Used mainly byJTASessionContextfor current session processing.- Specified by:
openSessionin interfaceSessionFactoryImplementor- Parameters:
connection- The external jdbc connection to use, if one (i.e., optional).flushBeforeCompletionEnabled- Should the session be auto-flushed prior to transaction completion?autoCloseSessionEnabled- Should the session be auto-closed after transaction completion?connectionReleaseMode- The release mode for managed jdbc connections.- Returns:
- An appropriate session.
- Throws:
HibernateException
-
getCurrentSession
Description copied from interface:SessionFactoryObtains 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.- Specified by:
getCurrentSessionin interfaceSessionFactory- Returns:
- The current session.
- Throws:
HibernateException- Indicates an issue locating a suitable current session.
-
getEntityPersister
Description copied from interface:SessionFactoryImplementorGet the persister for the named entity- Specified by:
getEntityPersisterin interfaceSessionFactoryImplementor- Parameters:
entityName- The name of the entity for which to retrieve the persister.- Returns:
- The persister
- Throws:
MappingException- Indicates persister could not be found with that name.
-
getCollectionPersister
Description copied from interface:SessionFactoryImplementorGet the persister object for a collection role.- Specified by:
getCollectionPersisterin interfaceSessionFactoryImplementor- Parameters:
role- The role (name) of the collection for which to retrieve the persister.- Returns:
- The persister
- Throws:
MappingException- Indicates persister could not be found with that role.
-
getSettings
- Specified by:
getSettingsin interfaceSessionFactoryImplementor
-
getDialect
Description copied from interface:SessionFactoryImplementorGet the SQL dialect. Shorthand forSessionFactoryImplementor.getSettings().Settings.getDialect()- Specified by:
getDialectin interfaceSessionFactoryImplementor- Returns:
- The dialect
-
getInterceptor
Description copied from interface:SessionFactoryImplementorGet the factory scoped interceptor for this factory.- Specified by:
getInterceptorin interfaceSessionFactoryImplementor- Returns:
- The factory scope interceptor, or null if none.
-
getTransactionFactory
-
getTransactionManager
Description copied from interface:SessionFactoryImplementorGet the JTA transaction manager- Specified by:
getTransactionManagerin interfaceSessionFactoryImplementor
-
getSQLExceptionConverter
Description copied from interface:SessionFactoryImplementorRetrieves the SQLExceptionConverter in effect for this SessionFactory.- Specified by:
getSQLExceptionConverterin interfaceSessionFactoryImplementor- Returns:
- The SQLExceptionConverter for this SessionFactory.
-
getCollectionRolesByEntityParticipant
Description copied from interface:SessionFactoryImplementorRetrieves a set of all the collection roles in which the given entity is a participant, as either an index or an element.- Specified by:
getCollectionRolesByEntityParticipantin interfaceSessionFactoryImplementor- Parameters:
entityName- The entity name for which to get the collection roles.- Returns:
- set of all the collection roles in which the given entityName participates.
-
getReference
- Specified by:
getReferencein interfaceReferenceable- Throws:
NamingException
-
getNamedQuery
- Specified by:
getNamedQueryin interfaceSessionFactoryImplementor
-
getNamedSQLQuery
- Specified by:
getNamedSQLQueryin interfaceSessionFactoryImplementor
-
getResultSetMapping
- Specified by:
getResultSetMappingin interfaceSessionFactoryImplementor
-
getIdentifierType
- Specified by:
getIdentifierTypein interfaceMapping- Throws:
MappingException
-
getIdentifierPropertyName
- Specified by:
getIdentifierPropertyNamein interfaceMapping- Throws:
MappingException
-
getReturnTypes
Description copied from interface:SessionFactoryImplementorGet the return types of a query- Specified by:
getReturnTypesin interfaceSessionFactoryImplementor- Throws:
HibernateException
-
getReturnAliases
Description copied from interface:SessionFactoryImplementorGet the return aliases of a query- Specified by:
getReturnAliasesin interfaceSessionFactoryImplementor- Throws:
HibernateException
-
getClassMetadata
Description copied from interface:SessionFactoryRetrieve theClassMetadataassociated with the given entity class.- Specified by:
getClassMetadatain interfaceSessionFactory- Parameters:
persistentClass- 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.
-
getCollectionMetadata
Description copied from interface:SessionFactoryGet theCollectionMetadataassociated with the named collection role.- Specified by:
getCollectionMetadatain interfaceSessionFactory- 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.
-
getClassMetadata
Description copied from interface:SessionFactoryRetrieve theClassMetadataassociated with the given entity class.- Specified by:
getClassMetadatain interfaceSessionFactory- 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.
-
getImplementors
Return the names of all persistent (mapped) classes that extend or implement the given class or interface, accounting for implicit/explicit polymorphism settings and excluding mapped subclasses/joined-subclasses of other classes in the result.- Specified by:
getImplementorsin interfaceSessionFactoryImplementor- Throws:
MappingException
-
getImportedClassName
Description copied from interface:SessionFactoryImplementorGet a class name, using query language imports- Specified by:
getImportedClassNamein interfaceSessionFactoryImplementor
-
getAllClassMetadata
Description copied from interface:SessionFactoryRetrieve theClassMetadatafor all mapped entities.- Specified by:
getAllClassMetadatain interfaceSessionFactory- Returns:
- A map containing all
ClassMetadatakeyed by the correspondingStringentity-name. - Throws:
HibernateException- Generally empty map is returned instead of throwing.
-
getAllCollectionMetadata
Description copied from interface:SessionFactoryGet theCollectionMetadatafor all mapped collections- Specified by:
getAllCollectionMetadatain interfaceSessionFactory- Returns:
- a map from String to CollectionMetadata
- Throws:
HibernateException- Generally empty map is returned instead of throwing.
-
getReferencedPropertyType
public Type getReferencedPropertyType(String className, String propertyName) throws MappingException - Specified by:
getReferencedPropertyTypein interfaceMapping- Throws:
MappingException
-
getConnectionProvider
Description copied from interface:SessionFactoryImplementorGet the connection provider- Specified by:
getConnectionProviderin interfaceSessionFactoryImplementor
-
close
Closes the session factory, releasing all held resources.- cleans up used cache regions and "stops" the cache provider.
- close the JDBC connection
- remove the JNDI binding
- Specified by:
closein interfaceSessionFactory- Throws:
HibernateException- Indicates an issue closing the factory.
-
getCache
Description copied from interface:SessionFactoryObtain direct access to the underlying cache regions.- Specified by:
getCachein interfaceSessionFactory- Returns:
- The direct cache access API.
-
evictEntity
Description copied from interface:SessionFactoryEvict 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.- Specified by:
evictEntityin interfaceSessionFactory- 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.
-
evictEntity
Description copied from interface:SessionFactoryEvict 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.- Specified by:
evictEntityin interfaceSessionFactory- 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.
-
evict
Description copied from interface:SessionFactoryEvict 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.- Specified by:
evictin interfaceSessionFactory- 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.
-
evict
Description copied from interface:SessionFactoryEvict 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.- Specified by:
evictin interfaceSessionFactory- 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.
-
evictCollection
Description copied from interface:SessionFactoryEvict 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.- Specified by:
evictCollectionin interfaceSessionFactory- 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.
-
evictCollection
Description copied from interface:SessionFactoryEvict 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.- Specified by:
evictCollectionin interfaceSessionFactory- 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.
-
evictQueries
Description copied from interface:SessionFactoryEvict any query result sets cached in the default query cache region.- Specified by:
evictQueriesin interfaceSessionFactory- Throws:
HibernateException- Indicate a problem communicating with underlying cache impl.
-
evictQueries
Description copied from interface:SessionFactoryEvict any query result sets cached in the named query cache region.- Specified by:
evictQueriesin interfaceSessionFactory- Parameters:
regionName- 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.
-
getUpdateTimestampsCache
Description copied from interface:SessionFactoryImplementorGet the cache of table update timestamps- Specified by:
getUpdateTimestampsCachein interfaceSessionFactoryImplementor
-
getQueryCache
Description copied from interface:SessionFactoryImplementorGet the default query cache- Specified by:
getQueryCachein interfaceSessionFactoryImplementor
-
getQueryCache
Description copied from interface:SessionFactoryImplementorGet a particular named query cache, or the default cache- Specified by:
getQueryCachein interfaceSessionFactoryImplementor- Parameters:
regionName- the name of the cache region, or null for the default query cache- Returns:
- the existing cache, or a newly created cache if none by that region name
- Throws:
HibernateException
-
getSecondLevelCacheRegion
Description copied from interface:SessionFactoryImplementorGet a named second-level cache region- Specified by:
getSecondLevelCacheRegionin interfaceSessionFactoryImplementor- Parameters:
regionName- The name of the region to retrieve.- Returns:
- The region
-
getAllSecondLevelCacheRegions
Description copied from interface:SessionFactoryImplementorGet a map of all the second level cache regions currently maintained in this session factory. The map is structured with the region name as the key and theRegioninstances as the values.- Specified by:
getAllSecondLevelCacheRegionsin interfaceSessionFactoryImplementor- Returns:
- The map of regions
-
isClosed
public boolean isClosed()Description copied from interface:SessionFactoryIs this factory already closed?- Specified by:
isClosedin interfaceSessionFactory- Returns:
- True if this factory is already closed; false otherwise.
-
getStatistics
Description copied from interface:SessionFactoryRetrieve the statistics fopr this factory.- Specified by:
getStatisticsin interfaceSessionFactory- Returns:
- The statistics.
-
getStatisticsImplementor
Description copied from interface:SessionFactoryImplementorStatistics SPI- Specified by:
getStatisticsImplementorin interfaceSessionFactoryImplementor
-
getFilterDefinition
Description copied from interface:SessionFactoryObtain the definition of a filter by name.- Specified by:
getFilterDefinitionin interfaceSessionFactory- 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
Description copied from interface:SessionFactoryDetermine if this session factory contains a fetch profile definition registered under the given name.- Specified by:
containsFetchProfileDefinitionin interfaceSessionFactory- Parameters:
name- The name to check- Returns:
- True if there is such a fetch profile; false otherwise.
-
getDefinedFilterNames
Description copied from interface:SessionFactoryObtain a set of the names of all filters defined on this SessionFactory.- Specified by:
getDefinedFilterNamesin interfaceSessionFactory- Returns:
- The set of filter names.
-
getBatcherFactory
-
getIdentifierGenerator
Description copied from interface:SessionFactoryImplementorGet the identifier generator for the hierarchy- Specified by:
getIdentifierGeneratorin interfaceSessionFactoryImplementor
-
getEventListeners
-
getEntityNotFoundDelegate
- Specified by:
getEntityNotFoundDelegatein interfaceSessionFactoryImplementor
-
getSqlFunctionRegistry
- Specified by:
getSqlFunctionRegistryin interfaceSessionFactoryImplementor
-
getFetchProfile
Description copied from interface:SessionFactoryImplementorRetrieve fetch profile by name.- Specified by:
getFetchProfilein interfaceSessionFactoryImplementor- Parameters:
name- The name of the profile to retrieve.- Returns:
- The profile definition
-
getFactoryObserver
Description copied from interface:SessionFactoryImplementorReturn the SessionFactoryObserver attached to the SessionFactory if any- Specified by:
getFactoryObserverin interfaceSessionFactoryImplementor- Returns:
-
getTypeHelper
Description copied from interface:SessionFactoryRetrieve this factory'sTypeHelper- Specified by:
getTypeHelperin interfaceSessionFactory- Returns:
- The factory's
TypeHelper
-