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 org. 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 org.
with org. there instead.
setDataSource, setPackagesToScan, HibernateTransactionManager, LocalSessionFactoryBuilder, org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
| Modifier and Type | Field and Description |
|---|---|
| private Class | |
| private String[] | |
| private ConfigurableListableBeanFactory | |
| private AsyncTaskExecutor | |
| private Resource[] | |
| private RegionFactory | |
| private Resource[] | |
| private Configuration | |
| private CurrentTenantIdentifierResolver | |
| private DataSource | |
| private Interceptor | |
| private TypeFilter[] | |
| private Integrator[] | |
| private Properties | |
| private ImplicitNamingStrategy | |
| private Object | |
| private Resource[] | |
| private Resource[] | |
| private Resource[] | |
| private String[] | |
| private MetadataSources | |
| private boolean | |
| private MultiTenantConnectionProvider | |
| private String[] | |
| private PhysicalNamingStrategy | |
| private ResourcePatternResolver | |
| private SessionFactory | sessionFactory
References Deprecated
SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.
|
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| protected SessionFactory | Returns: the SessionFactory instancea LocalSessionFactoryBuilder prepared by this LocalSessionFactoryBean sfb)
References Deprecated
SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.
Subclasses can override this method to perform custom initialization of the SessionFactory instance, creating it via the given Configuration object that got prepared by this LocalSessionFactoryBean. |
| public void | destroy()
Implements org. Invoked by the containing |
| public final Configuration | |
| public Properties | |
| public MetadataSources | Returns: the MetadataSources to use (nevernull)Determine the Hibernate |
| public SessionFactory | getObject()
Implements org.
References Deprecated
SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.
Return an instance (possibly shared or independent) of the object managed by this factory. |
| public Class | getObjectType()
Implements org. Return the type of object that this FactoryBean creates,
or |
| public ResourceLoader | Returns: the ResourceLoader to use (nevernull)Determine the Spring |
| public boolean | isSingleton()
Overrides default org. Is the object managed by this factory a singleton? |
| public void | setAnnotatedClasses(Class<?>... annotatedClasses)
Specify annotated entity classes to register with this Hibernate SessionFactory. |
| public void | setAnnotatedPackages(String... annotatedPackages)
Specify the names of annotated packages, for which package-level annotation metadata will be read. |
| public void | setBeanFactory(BeanFactory
owning BeanFactory (never beanFactory)null).
The bean can immediately call methods on the factory.Implements org. Accept the containing |
| public void | setBootstrapExecutor(AsyncTaskExecutor bootstrapExecutor)
Specify an asynchronous executor for background bootstrapping,
e.g. a |
| public void | setCacheableMappingLocations(Resource... cacheableMappingLocations)
Set locations of cacheable Hibernate mapping files, for example as web app resource "/WEB-INF/mapping/example.hbm.xml". |
| public void | setCacheRegionFactory(RegionFactory cacheRegionFactory)
Set the Hibernate |
| public void | setConfigLocation(Resource configLocation)
Set the location of a single Hibernate XML config file, for example as classpath resource "classpath:hibernate.cfg.xml". |
| public void | setConfigLocations(Resource... configLocations)
Set the locations of multiple Hibernate XML config files, for example as classpath resources "classpath:hibernate.cfg.xml,classpath:extension.cfg.xml". |
| public void | setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver)
Set a |
| public void | |
| public void | setEntityInterceptor(Interceptor entityInterceptor)
Set a Hibernate entity interceptor that allows to inspect and change property values before writing to and reading from the database. |
| public void | setEntityTypeFilters(TypeFilter... entityTypeFilters)
Specify custom type filters for Spring-based scanning for entity classes. |
| public void | setHibernateIntegrators(Integrator... hibernateIntegrators)
Specify one or more Hibernate |
| public void | setHibernateProperties(Properties hibernateProperties)
Set Hibernate properties, such as "hibernate.dialect". |
| public void | setImplicitNamingStrategy(ImplicitNamingStrategy implicitNamingStrategy)
Set a Hibernate 5 |
| public void | setJtaTransactionManager(Object jtaTransactionManager)
Set the Spring |
| public void | setMappingDirectoryLocations(Resource... mappingDirectoryLocations)
Set locations of directories that contain Hibernate mapping resources, like "WEB-INF/mappings". |
| public void | setMappingJarLocations(Resource... mappingJarLocations)
Set locations of jar files that contain Hibernate mapping resources, like "WEB-INF/lib/example.hbm.jar". |
| public void | setMappingLocations(Resource... mappingLocations)
Set locations of Hibernate mapping files, for example as classpath resource "classpath:example.hbm.xml". |
| public void | setMappingResources(String... mappingResources)
Set Hibernate mapping resources to be found in the class path, like "example.hbm.xml" or "mypackage/example.hbm.xml". |
| public void | setMetadataSources(MetadataSources metadataSources)
Specify a Hibernate |
| public void | setMultiTenantConnectionProvider(MultiTenantConnectionProvider multiTenantConnectionProvider)
Set a |
| public void | setPackagesToScan(String... packagesToScan)
Specify packages to search for autodetection of your entity classes in the classpath. |
| public void | setPhysicalNamingStrategy(PhysicalNamingStrategy physicalNamingStrategy)
Set a Hibernate 5 |
| public void | setResourceLoader(ResourceLoader
the ResourceLoader to use (never resourceLoader)null)Implements org. Specify a Spring |
| annotatedClasses | back to summary |
|---|---|
| private Class<?>[] annotatedClasses
| |
| annotatedPackages | back to summary |
|---|---|
| private String[] annotatedPackages
| |
| beanFactory | back to summary |
|---|---|
| private ConfigurableListableBeanFactory beanFactory
| |
| bootstrapExecutor | back to summary |
|---|---|
| private AsyncTaskExecutor bootstrapExecutor
| |
| cacheableMappingLocations | back to summary |
|---|---|
| private Resource[] cacheableMappingLocations
| |
| cacheRegionFactory | back to summary |
|---|---|
| private RegionFactory cacheRegionFactory
| |
| configLocations | back to summary |
|---|---|
| private Resource[] configLocations
| |
| configuration | back to summary |
|---|---|
| private Configuration configuration
| |
| currentTenantIdentifierResolver | back to summary |
|---|---|
| private CurrentTenantIdentifierResolver currentTenantIdentifierResolver
| |
| dataSource | back to summary |
|---|---|
| private DataSource dataSource
| |
| entityInterceptor | back to summary |
|---|---|
| private Interceptor entityInterceptor
| |
| entityTypeFilters | back to summary |
|---|---|
| private TypeFilter[] entityTypeFilters
| |
| hibernateIntegrators | back to summary |
|---|---|
| private Integrator[] hibernateIntegrators
| |
| hibernateProperties | back to summary |
|---|---|
| private Properties hibernateProperties
| |
| implicitNamingStrategy | back to summary |
|---|---|
| private ImplicitNamingStrategy implicitNamingStrategy
| |
| jtaTransactionManager | back to summary |
|---|---|
| private Object jtaTransactionManager
| |
| mappingDirectoryLocations | back to summary |
|---|---|
| private Resource[] mappingDirectoryLocations
| |
| mappingJarLocations | back to summary |
|---|---|
| private Resource[] mappingJarLocations
| |
| mappingLocations | back to summary |
|---|---|
| private Resource[] mappingLocations
| |
| mappingResources | back to summary |
|---|---|
| private String[] mappingResources
| |
| metadataSources | back to summary |
|---|---|
| private MetadataSources metadataSources
| |
| metadataSourcesAccessed | back to summary |
|---|---|
| private boolean metadataSourcesAccessed | |
| multiTenantConnectionProvider | back to summary |
|---|---|
| private MultiTenantConnectionProvider multiTenantConnectionProvider
| |
| packagesToScan | back to summary |
|---|---|
| private String[] packagesToScan
| |
| physicalNamingStrategy | back to summary |
|---|---|
| private PhysicalNamingStrategy physicalNamingStrategy
| |
| resourcePatternResolver | back to summary |
|---|---|
| private ResourcePatternResolver resourcePatternResolver
| |
| sessionFactory | back to summary |
|---|---|
| private SessionFactory sessionFactory
References Deprecated
See corresponding docs for further information. | |
| LocalSessionFactoryBean | back to summary |
|---|---|
| public LocalSessionFactoryBean() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() throws IOException Implements org. Doc from org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
| |
| buildSessionFactory | back to summary |
|---|---|
| protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb)
References Deprecated
See corresponding docs for further information. Subclasses can override this method to perform custom initialization of the SessionFactory instance, creating it via the given Configuration object that got prepared by this LocalSessionFactoryBean. The default implementation invokes LocalSessionFactoryBuilder's buildSessionFactory. A custom implementation could prepare the instance in a specific way (e.g. applying a custom ServiceRegistry) or use a custom SessionFactoryImpl subclass.
| |
| destroy | back to summary |
|---|---|
| public void destroy() Implements org. Doc from org. Invoked by the containing
| |
| getConfiguration | back to summary |
|---|---|
| public final Configuration getConfiguration() Return the Hibernate Configuration object used to build the SessionFactory. Allows for access to configuration metadata stored there (rarely needed).
| |
| getHibernateProperties | back to summary |
|---|---|
| public Properties getHibernateProperties() Return the Hibernate properties, if any. Mainly available for configuration through property paths that specify individual keys. | |
| getMetadataSources | back to summary |
|---|---|
| public MetadataSources getMetadataSources() Determine the Hibernate Can also be externally called to initialize and pre-populate a
| |
| getObject | back to summary |
|---|---|
| public SessionFactory getObject() Implements org. Doc from org. References Deprecated
See corresponding docs for further information. Return an instance (possibly shared or independent) of the object managed by this factory. As with a If this FactoryBean is not fully initialized yet at the time of
the call (for example because it is involved in a circular reference),
throw a corresponding As of Spring 2.0, FactoryBeans are allowed to return
| |
| getObjectType | back to summary |
|---|---|
| public Class Implements org. Doc from org. Return the type of object that this FactoryBean creates,
or This allows one to check for specific types of beans without instantiating objects, for example on autowiring. In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too. This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available. Note Autowiring will simply ignore FactoryBeans that return
| |
| getResourceLoader | back to summary |
|---|---|
| public ResourceLoader getResourceLoader() Determine the Spring
| |
| isSingleton | back to summary |
|---|---|
| public boolean isSingleton() Overrides default org. Doc from org. Is the object managed by this factory a singleton? That is,
will Note If a FactoryBean indicates to hold a singleton object,
the object returned from The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there. Note This method returning The default implementation returns
| |
| setAnnotatedClasses | back to summary |
|---|---|
| public void setAnnotatedClasses(Class<?>... annotatedClasses) Specify annotated entity classes to register with this Hibernate SessionFactory. | |
| setAnnotatedPackages | back to summary |
|---|---|
| public void setAnnotatedPackages(String... annotatedPackages) Specify the names of annotated packages, for which package-level annotation metadata will be read.
| |
| setBeanFactory | back to summary |
|---|---|
| public void setBeanFactory(BeanFactory beanFactory) Implements org. Accept the containing
| |
| setBootstrapExecutor | back to summary |
|---|---|
| public void setBootstrapExecutor(AsyncTaskExecutor bootstrapExecutor) Specify an asynchronous executor for background bootstrapping,
e.g. a
| |
| setCacheableMappingLocations | back to summary |
|---|---|
| public void setCacheableMappingLocations(Resource... cacheableMappingLocations) Set locations of cacheable Hibernate mapping files, for example as web app resource "/WEB-INF/mapping/example.hbm.xml". Supports any resource location via Spring's resource abstraction, as long as the resource can be resolved in the file system. Can be used to add to mappings from a Hibernate XML config file, or to specify all mappings locally.
| |
| setCacheRegionFactory | back to summary |
|---|---|
| public void setCacheRegionFactory(RegionFactory cacheRegionFactory) Set the Hibernate Note If this is set, the Hibernate settings should not define a cache provider to avoid meaningless double configuration.
| |
| setConfigLocation | back to summary |
|---|---|
| public void setConfigLocation(Resource configLocation) Set the location of a single Hibernate XML config file, for example as classpath resource "classpath:hibernate.cfg.xml". Note Can be omitted when all necessary properties and mapping resources are specified locally via this bean. | |
| setConfigLocations | back to summary |
|---|---|
| public void setConfigLocations(Resource... configLocations) Set the locations of multiple Hibernate XML config files, for example as classpath resources "classpath:hibernate.cfg.xml,classpath:extension.cfg.xml". Note Can be omitted when all necessary properties and mapping resources are specified locally via this bean. | |
| setCurrentTenantIdentifierResolver | back to summary |
|---|---|
| public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) Set a | |
| setDataSource | back to summary |
|---|---|
| public void setDataSource(DataSource dataSource) Set the DataSource to be used by the SessionFactory. If set, this will override corresponding settings in Hibernate properties. If this is set, the Hibernate settings should not define a connection provider to avoid meaningless double configuration. | |
| setEntityInterceptor | back to summary |
|---|---|
| public void setEntityInterceptor(Interceptor entityInterceptor) Set a Hibernate entity interceptor that allows to inspect and change property values before writing to and reading from the database. Will get applied to any new Session created by this factory.
| |
| setEntityTypeFilters | back to summary |
|---|---|
| public void setEntityTypeFilters(TypeFilter... entityTypeFilters) Specify custom type filters for Spring-based scanning for entity classes. Default is to search all specified packages for classes annotated with
| |
| setHibernateIntegrators | back to summary |
|---|---|
| public void setHibernateIntegrators(Integrator... hibernateIntegrators) Specify one or more Hibernate This will only be applied for an internally built
| |
| setHibernateProperties | back to summary |
|---|---|
| public void setHibernateProperties(Properties hibernateProperties) Set Hibernate properties, such as "hibernate.dialect". Note Do not specify a transaction provider here when using Spring-driven transactions. It is also advisable to omit connection provider settings and use a Spring-set DataSource instead.
| |
| setImplicitNamingStrategy | back to summary |
|---|---|
| public void setImplicitNamingStrategy(ImplicitNamingStrategy implicitNamingStrategy) Set a Hibernate 5 | |
| setJtaTransactionManager | back to summary |
|---|---|
| public void setJtaTransactionManager(Object jtaTransactionManager) Set the Spring | |
| setMappingDirectoryLocations | back to summary |
|---|---|
| public void setMappingDirectoryLocations(Resource... mappingDirectoryLocations) Set locations of directories that contain Hibernate mapping resources, like "WEB-INF/mappings". Can be used to add to mappings from a Hibernate XML config file, or to specify all mappings locally.
| |
| setMappingJarLocations | back to summary |
|---|---|
| public void setMappingJarLocations(Resource... mappingJarLocations) Set locations of jar files that contain Hibernate mapping resources, like "WEB-INF/lib/example.hbm.jar". Can be used to add to mappings from a Hibernate XML config file, or to specify all mappings locally.
| |
| setMappingLocations | back to summary |
|---|---|
| public void setMappingLocations(Resource... mappingLocations) Set locations of Hibernate mapping files, for example as classpath resource "classpath:example.hbm.xml". Supports any resource location via Spring's resource abstraction, for example relative paths like "WEB-INF/mappings/example.hbm.xml" when running in an application context. Can be used to add to mappings from a Hibernate XML config file, or to specify all mappings locally.
| |
| setMappingResources | back to summary |
|---|---|
| public void setMappingResources(String... mappingResources) Set Hibernate mapping resources to be found in the class path, like "example.hbm.xml" or "mypackage/example.hbm.xml". Analogous to mapping entries in a Hibernate XML config file. Alternative to the more generic setMappingLocations method. Can be used to add to mappings from a Hibernate XML config file, or to specify all mappings locally.
| |
| setMetadataSources | back to summary |
|---|---|
| public void setMetadataSources(MetadataSources metadataSources) Specify a Hibernate | |
| setMultiTenantConnectionProvider | back to summary |
|---|---|
| public void setMultiTenantConnectionProvider(MultiTenantConnectionProvider multiTenantConnectionProvider) Set a
| |
| setPackagesToScan | back to summary |
|---|---|
| public void setPackagesToScan(String... packagesToScan) Specify packages to search for autodetection of your entity classes in the
classpath. This is analogous to Spring's component-scan feature
( | |
| setPhysicalNamingStrategy | back to summary |
|---|---|
| public void setPhysicalNamingStrategy(PhysicalNamingStrategy physicalNamingStrategy) Set a Hibernate 5 | |
| setResourceLoader | back to summary |
|---|---|
| public void setResourceLoader(ResourceLoader resourceLoader) Implements org. Specify a Spring
| |