Class LocalSessionFactoryBuilder

java.lang.Object
org.hibernate.cfg.Configuration
org.springframework.orm.hibernate5.LocalSessionFactoryBuilder

public class LocalSessionFactoryBuilder extends Configuration
A Spring-provided extension of the standard Hibernate Configuration class, adding SpringSessionContext as a default and providing convenient ways to specify a JDBC DataSource and an application class loader.

This is designed for programmatic use, e.g. in @Bean factory methods; consider using LocalSessionFactoryBean for XML bean definition files. Typically combined with HibernateTransactionManager for declarative transactions against the SessionFactory and its JDBC DataSource.

Compatible with Hibernate 5.5/5.6, as of Spring 6.0. This Hibernate-specific factory builder can also be a convenient way to set up a JPA EntityManagerFactory since the Hibernate SessionFactory natively exposes the JPA EntityManagerFactory interface as well now.

This builder supports Hibernate BeanContainer integration, MetadataSources from custom BootstrapServiceRegistryBuilder setup, as well as other advanced Hibernate configuration options beyond the standard JPA bootstrap contract.

Since:
4.2
Author:
Juergen Hoeller
See Also:
  • Constructor Details

    • LocalSessionFactoryBuilder

      public LocalSessionFactoryBuilder(@Nullable DataSource dataSource)
      Create a new LocalSessionFactoryBuilder for the given DataSource.
      Parameters:
      dataSource - the JDBC DataSource that the resulting Hibernate SessionFactory should be using (may be null)
    • LocalSessionFactoryBuilder

      public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ClassLoader classLoader)
      Create a new LocalSessionFactoryBuilder for the given DataSource.
      Parameters:
      dataSource - the JDBC DataSource that the resulting Hibernate SessionFactory should be using (may be null)
      classLoader - the ClassLoader to load application classes from
    • LocalSessionFactoryBuilder

      public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ResourceLoader resourceLoader)
      Create a new LocalSessionFactoryBuilder for the given DataSource.
      Parameters:
      dataSource - the JDBC DataSource that the resulting Hibernate SessionFactory should be using (may be null)
      resourceLoader - the ResourceLoader to load application classes from
    • LocalSessionFactoryBuilder

      public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ResourceLoader resourceLoader, org.hibernate.boot.MetadataSources metadataSources)
      Create a new LocalSessionFactoryBuilder for the given DataSource.
      Parameters:
      dataSource - the JDBC DataSource that the resulting Hibernate SessionFactory should be using (may be null)
      resourceLoader - the ResourceLoader to load application classes from
      metadataSources - the Hibernate MetadataSources service to use (e.g. reusing an existing one)
      Since:
      4.3
  • Method Details