{@link org.springframework.beans.factory.FactoryBean} that creates aHibernate {@link org.hibernate.SessionFactory}. This is the usual way to set up a shared Hibernate SessionFactory in a Spring application context; the SessionFactory can then be passed to Hibernate-based DAOs via dependency injection.
Configuration settings can either be read from a Hibernate XML file, specified as "configLocation", or completely via this class. A typical local configuration consists of one or more "mappingResources", various "hibernateProperties" (not strictly necessary), and a "dataSource" that the SessionFactory should use. The latter can also be specified via Hibernate properties, but "dataSource" supports any Spring-configured DataSource, instead of relying on Hibernate's own connection providers.
This SessionFactory handling strategy is appropriate for most types of applications, from Hibernate-only single database apps to ones that need distributed transactions. Either {@link HibernateTransactionManager} or{@link org.springframework.transaction.jta.JtaTransactionManager} can beused for transaction demarcation, with the latter only necessary for transactions which span multiple databases.
This factory bean will by default expose a transaction-aware SessionFactory proxy, letting data access code work with the plain Hibernate SessionFactory and its getCurrentSession()
method, while still being able to participate in current Spring-managed transactions: with any transaction management strategy, either local or JTA / EJB CMT, and any transaction synchronization mechanism, either Spring or JTA. Furthermore, getCurrentSession()
will also seamlessly work with a request-scoped Session managed by {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /{@link org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor}.
Requires Hibernate 3.2 or later; tested with 3.3, 3.5 and 3.6. Note that this factory will use "on_close" as default Hibernate connection release mode, unless in the case of a "jtaTransactionManager" specified, for the reason that this is appropriate for most Spring-based applications (in particular when using Spring's HibernateTransactionManager).
@author Juergen Hoeller
@since 1.2
@see HibernateTemplate#setSessionFactory
@see HibernateTransactionManager#setSessionFactory
@see #setExposeTransactionAwareSessionFactory
@see #setJtaTransactionManager
@see org.hibernate.SessionFactory#getCurrentSession()
@see HibernateTransactionManager