Class LocalSessionFactoryBean

All Implemented Interfaces:
Aware, BeanFactoryAware, DisposableBean, FactoryBean<SessionFactory>, InitializingBean, ResourceLoaderAware, PersistenceExceptionTranslator

FactoryBean that creates a 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 data access objects via dependency injection.

Compatible with Hibernate ORM 5.5/5.6, as of Spring Framework 6.0. This Hibernate-specific LocalSessionFactoryBean can be an immediate alternative to LocalContainerEntityManagerFactoryBean for common JPA purposes: The Hibernate SessionFactory will natively expose the JPA EntityManagerFactory interface as well, and Hibernate BeanContainer integration will be registered out of the box. In combination with HibernateTransactionManager, this naturally allows for mixing JPA access code with native Hibernate access code within the same transaction.

NOTE: Hibernate ORM 6.x is officially only supported as a JPA provider. Please use LocalContainerEntityManagerFactoryBean with JpaTransactionManager there instead.

Juergen Hoeller
See Also: