Top Description Fields Constructors Methods
org.springframework.orm.hibernate5

public Class LocalSessionFactoryBean

extends HibernateExceptionTranslator
implements FactoryBean<SessionFactory>, ResourceLoaderAware, BeanFactoryAware, InitializingBean, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware, org.springframework.context.ResourceLoaderAware, org.springframework.beans.factory.FactoryBean
Imports
java.io.File, .IOException, java.util.Properties, javax.sql.DataSource, org.hibernate.Interceptor, .SessionFactory, org.hibernate.boot.MetadataSources, org.hibernate.boot.model.naming.ImplicitNamingStrategy, .PhysicalNamingStrategy, org.hibernate.boot.registry.BootstrapServiceRegistryBuilder, org.hibernate.cache.spi.RegionFactory, org.hibernate.cfg.Configuration, org.hibernate.context.spi.CurrentTenantIdentifierResolver, org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider, org.hibernate.integrator.spi.Integrator, org.hibernate.service.ServiceRegistry, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, .DisposableBean, .FactoryBean, .InitializingBean, org.springframework.beans.factory.config.ConfigurableListableBeanFactory, org.springframework.context.ResourceLoaderAware, org.springframework.core.io.ClassPathResource, .Resource, .ResourceLoader, org.springframework.core.io.support.PathMatchingResourcePatternResolver, .ResourcePatternResolver, .ResourcePatternUtils, org.springframework.core.task.AsyncTaskExecutor, org.springframework.core.type.filter.TypeFilter, org.springframework.lang.Nullable

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.springframework.orm.jpa.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 org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean with org.springframework.orm.jpa.JpaTransactionManager there instead.

Author
Juergen Hoeller
Since
4.2
See Also
setDataSource, setPackagesToScan, HibernateTransactionManager, LocalSessionFactoryBuilder, org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean

Field Summary

Modifier and TypeField 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

Deprecated as a consequence of SessionFactory being deprecated.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

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 instance
buildSessionFactory
(LocalSessionFactoryBuilder
a LocalSessionFactoryBuilder prepared by this LocalSessionFactoryBean
sfb
)

Deprecated as a consequence of SessionFactory being deprecated.
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.springframework.beans.factory.DisposableBean.destroy.

Invoked by the containing BeanFactory on destruction of a bean.
public final Configuration
getConfiguration()

Return the Hibernate Configuration object used to build the SessionFactory.

public Properties
getHibernateProperties()

Return the Hibernate properties, if any.

public MetadataSources

Returns:

the MetadataSources to use (never null)
getMetadataSources
()

Determine the Hibernate MetadataSources to use.

public SessionFactory
getObject()

Implements org.springframework.beans.factory.FactoryBean.getObject.

Deprecated as a consequence of SessionFactory being deprecated.
Return an instance (possibly shared or independent) of the object managed by this factory.
public Class<?>
getObjectType()

Implements org.springframework.beans.factory.FactoryBean.getObjectType.

Return the type of object that this FactoryBean creates, or null if not known in advance.
public ResourceLoader

Returns:

the ResourceLoader to use (never null)
getResourceLoader
()

Determine the Spring ResourceLoader to use for Hibernate metadata.

public boolean
isSingleton()

Overrides default org.springframework.beans.factory.FactoryBean.isSingleton.

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 null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Accept the containing BeanFactory, registering corresponding Hibernate org.hibernate.resource.beans.container.spi.BeanContainer integration for it if possible.
public void
setBootstrapExecutor(AsyncTaskExecutor bootstrapExecutor)

Specify an asynchronous executor for background bootstrapping, e.g. a org.springframework.core.task.SimpleAsyncTaskExecutor.

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 RegionFactory to use for the SessionFactory.

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 CurrentTenantIdentifierResolver to be passed on to the SessionFactory.

public void
setDataSource(DataSource dataSource)

Set the DataSource to be used by the SessionFactory.

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 Integrator implementations to apply.

public void
setHibernateProperties(Properties hibernateProperties)

Set Hibernate properties, such as "hibernate.dialect".

public void
setImplicitNamingStrategy(ImplicitNamingStrategy implicitNamingStrategy)

Set a Hibernate 5 ImplicitNamingStrategy for the SessionFactory.

public void
setJtaTransactionManager(Object jtaTransactionManager)

Set the Spring org.springframework.transaction.jta.JtaTransactionManager or the JTA jakarta.transaction.TransactionManager to be used with Hibernate, if any.

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 MetadataSources service to use (e.g. reusing an existing one), potentially populated with a custom Hibernate bootstrap org.hibernate.service.ServiceRegistry as well.

public void
setMultiTenantConnectionProvider(MultiTenantConnectionProvider multiTenantConnectionProvider)

Set a MultiTenantConnectionProvider to be passed on to the SessionFactory.

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 PhysicalNamingStrategy for the SessionFactory.

public void
setResourceLoader(ResourceLoader
the ResourceLoader to use (never null)
resourceLoader
)

Implements org.springframework.context.ResourceLoaderAware.setResourceLoader.

Specify a Spring ResourceLoader to use for Hibernate metadata.
Inherited from org.springframework.orm.hibernate5.HibernateExceptionTranslator:
convertHibernateAccessExceptionsetJdbcExceptionTranslatortranslateExceptionIfPossible

Field Detail

annotatedClassesback to summary
private Class<?>[] annotatedClasses
Annotations
@Nullable
annotatedPackagesback to summary
private String[] annotatedPackages
Annotations
@Nullable
beanFactoryback to summary
private ConfigurableListableBeanFactory beanFactory
Annotations
@Nullable
bootstrapExecutorback to summary
private AsyncTaskExecutor bootstrapExecutor
Annotations
@Nullable
cacheableMappingLocationsback to summary
private Resource[] cacheableMappingLocations
Annotations
@Nullable
cacheRegionFactoryback to summary
private RegionFactory cacheRegionFactory
Annotations
@Nullable
configLocationsback to summary
private Resource[] configLocations
Annotations
@Nullable
configurationback to summary
private Configuration configuration
Annotations
@Nullable
currentTenantIdentifierResolverback to summary
private CurrentTenantIdentifierResolver currentTenantIdentifierResolver
Annotations
@Nullable
dataSourceback to summary
private DataSource dataSource
Annotations
@Nullable
entityInterceptorback to summary
private Interceptor entityInterceptor
Annotations
@Nullable
entityTypeFiltersback to summary
private TypeFilter[] entityTypeFilters
Annotations
@Nullable
hibernateIntegratorsback to summary
private Integrator[] hibernateIntegrators
Annotations
@Nullable
hibernatePropertiesback to summary
private Properties hibernateProperties
Annotations
@Nullable
implicitNamingStrategyback to summary
private ImplicitNamingStrategy implicitNamingStrategy
Annotations
@Nullable
jtaTransactionManagerback to summary
private Object jtaTransactionManager
Annotations
@Nullable
mappingDirectoryLocationsback to summary
private Resource[] mappingDirectoryLocations
Annotations
@Nullable
mappingJarLocationsback to summary
private Resource[] mappingJarLocations
Annotations
@Nullable
mappingLocationsback to summary
private Resource[] mappingLocations
Annotations
@Nullable
mappingResourcesback to summary
private String[] mappingResources
Annotations
@Nullable
metadataSourcesback to summary
private MetadataSources metadataSources
Annotations
@Nullable
metadataSourcesAccessedback to summary
private boolean metadataSourcesAccessed
multiTenantConnectionProviderback to summary
private MultiTenantConnectionProvider multiTenantConnectionProvider
Annotations
@Nullable
packagesToScanback to summary
private String[] packagesToScan
Annotations
@Nullable
physicalNamingStrategyback to summary
private PhysicalNamingStrategy physicalNamingStrategy
Annotations
@Nullable
resourcePatternResolverback to summary
private ResourcePatternResolver resourcePatternResolver
Annotations
@Nullable
sessionFactoryback to summary
private SessionFactory sessionFactory

Deprecated

as a consequence of SessionFactory being deprecated. See corresponding docs for further information.

Annotations
@Nullable

Constructor Detail

LocalSessionFactoryBeanback to summary
public LocalSessionFactoryBean()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws IOException

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

Annotations
@Override
buildSessionFactoryback to summary
protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb)

Deprecated

as a consequence of SessionFactory being 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.

Parameters
sfb:LocalSessionFactoryBuilder

a LocalSessionFactoryBuilder prepared by this LocalSessionFactoryBean

Returns:SessionFactory

the SessionFactory instance

See Also
LocalSessionFactoryBuilder#buildSessionFactory
destroyback to summary
public void destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Doc from org.springframework.beans.factory.DisposableBean.destroy.

Invoked by the containing BeanFactory on destruction of a bean.

Annotations
@Override
getConfigurationback 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).

Exceptions
IllegalStateException:
if the Configuration object has not been initialized yet
getHibernatePropertiesback to summary
public Properties getHibernateProperties()

Return the Hibernate properties, if any. Mainly available for configuration through property paths that specify individual keys.

getMetadataSourcesback to summary
public MetadataSources getMetadataSources()

Determine the Hibernate MetadataSources to use.

Can also be externally called to initialize and pre-populate a MetadataSources instance which is then going to be used for SessionFactory building.

Returns:MetadataSources

the MetadataSources to use (never null)

Since
4.3
See Also
LocalSessionFactoryBuilder#LocalSessionFactoryBuilder(DataSource, ResourceLoader, MetadataSources)
getObjectback to summary
public SessionFactory getObject()

Implements org.springframework.beans.factory.FactoryBean.getObject.

Doc from org.springframework.beans.factory.FactoryBean.getObject.

Deprecated

as a consequence of SessionFactory being deprecated. See corresponding docs for further information.

Return an instance (possibly shared or independent) of the object managed by this factory.

As with a BeanFactory, this allows support for both the Singleton and Prototype design pattern.

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 FactoryBeanNotInitializedException.

As of Spring 2.0, FactoryBeans are allowed to return null objects. The factory will consider this as normal value to be used; it will not throw a FactoryBeanNotInitializedException in this case anymore. FactoryBean implementations are encouraged to throw FactoryBeanNotInitializedException themselves now, as appropriate.

Returns:SessionFactory

an instance of the bean (can be null)

Annotations
@Override
@Nullable
getObjectTypeback to summary
public Class<?> getObjectType()

Implements org.springframework.beans.factory.FactoryBean.getObjectType.

Doc from org.springframework.beans.factory.FactoryBean.getObjectType.

Return the type of object that this FactoryBean creates, or null if not known in advance.

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 null here. Therefore, it is highly recommended to implement this method properly, using the current state of the FactoryBean.

Returns:Class<?>

the type of object that this FactoryBean creates, or null if not known at the time of the call

Annotations
@Override
getResourceLoaderback to summary
public ResourceLoader getResourceLoader()

Determine the Spring ResourceLoader to use for Hibernate metadata.

Returns:ResourceLoader

the ResourceLoader to use (never null)

Since
4.3
isSingletonback to summary
public boolean isSingleton()

Overrides default org.springframework.beans.factory.FactoryBean.isSingleton.

Doc from org.springframework.beans.factory.FactoryBean.isSingleton.

Is the object managed by this factory a singleton? That is, will getObject() always return the same object (a reference that can be cached)?

Note

If a FactoryBean indicates to hold a singleton object, the object returned from getObject() might get cached by the owning BeanFactory. Hence, do not return true unless the FactoryBean always exposes the same reference.

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 false does not necessarily indicate that returned objects are independent instances. An implementation of the extended SmartFactoryBean interface may explicitly indicate independent instances through its SmartFactoryBean#isPrototype() method. Plain FactoryBean implementations which do not implement this extended interface are simply assumed to always return independent instances if the isSingleton() implementation returns false.

The default implementation returns true, since a FactoryBean typically manages a singleton instance.

Returns:boolean

whether the exposed object is a singleton

Annotations
@Override
setAnnotatedClassesback to summary
public void setAnnotatedClasses(Class<?>... annotatedClasses)

Specify annotated entity classes to register with this Hibernate SessionFactory.

See Also
Configuration#addAnnotatedClass(Class)
setAnnotatedPackagesback to summary
public void setAnnotatedPackages(String... annotatedPackages)

Specify the names of annotated packages, for which package-level annotation metadata will be read.

See Also
Configuration#addPackage(String)
setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Accept the containing BeanFactory, registering corresponding Hibernate org.hibernate.resource.beans.container.spi.BeanContainer integration for it if possible. This requires a Spring ConfigurableListableBeanFactory.

Parameters
beanFactory:BeanFactory

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
Since
5.1
See Also
SpringBeanContainer, LocalSessionFactoryBuilder#setBeanContainer
setBootstrapExecutorback to summary
public void setBootstrapExecutor(AsyncTaskExecutor bootstrapExecutor)

Specify an asynchronous executor for background bootstrapping, e.g. a org.springframework.core.task.SimpleAsyncTaskExecutor.

SessionFactory initialization will then switch into background bootstrap mode, with a SessionFactory proxy immediately returned for injection purposes instead of waiting for Hibernate's bootstrapping to complete. However, note that the first actual call to a SessionFactory method will then block until Hibernate's bootstrapping completed, if not ready by then. For maximum benefit, make sure to avoid early SessionFactory calls in init methods of related beans, even for metadata introspection purposes.

Since
4.3
See Also
LocalSessionFactoryBuilder#buildSessionFactory(AsyncTaskExecutor)
setCacheableMappingLocationsback 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.

See Also
Configuration#addCacheableFile(File)
setCacheRegionFactoryback to summary
public void setCacheRegionFactory(RegionFactory cacheRegionFactory)

Set the Hibernate RegionFactory to use for the SessionFactory. Allows for using a Spring-managed RegionFactory instance.

Note

If this is set, the Hibernate settings should not define a cache provider to avoid meaningless double configuration.

Since
5.1
See Also
LocalSessionFactoryBuilder#setCacheRegionFactory
setConfigLocationback 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.

See Also
Configuration#configure(java.net.URL)
setConfigLocationsback 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.

See Also
Configuration#configure(java.net.URL)
setCurrentTenantIdentifierResolverback to summary
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver)

Set a CurrentTenantIdentifierResolver to be passed on to the SessionFactory.

See Also
LocalSessionFactoryBuilder#setCurrentTenantIdentifierResolver
setDataSourceback 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.

setEntityInterceptorback 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.

See Also
Configuration#setInterceptor
setEntityTypeFiltersback 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 @jakarta.persistence.Entity, @jakarta.persistence.Embeddable or @jakarta.persistence.MappedSuperclass.

See Also
setPackagesToScan
setHibernateIntegratorsback to summary
public void setHibernateIntegrators(Integrator... hibernateIntegrators)

Specify one or more Hibernate Integrator implementations to apply.

This will only be applied for an internally built MetadataSources instance. setMetadataSources effectively overrides such settings, with integrators to be applied to the externally built MetadataSources.

Since
5.1
See Also
setMetadataSources, BootstrapServiceRegistryBuilder#applyIntegrator
setHibernatePropertiesback 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.

See Also
setDataSource
setImplicitNamingStrategyback to summary
public void setImplicitNamingStrategy(ImplicitNamingStrategy implicitNamingStrategy)

Set a Hibernate 5 ImplicitNamingStrategy for the SessionFactory.

See Also
Configuration#setImplicitNamingStrategy
setJtaTransactionManagerback to summary
public void setJtaTransactionManager(Object jtaTransactionManager)

Set the Spring org.springframework.transaction.jta.JtaTransactionManager or the JTA jakarta.transaction.TransactionManager to be used with Hibernate, if any. Implicitly sets up JtaPlatform.

See Also
LocalSessionFactoryBuilder#setJtaTransactionManager
setMappingDirectoryLocationsback 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.

See Also
Configuration#addDirectory(File)
setMappingJarLocationsback 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.

See Also
Configuration#addJar(File)
setMappingLocationsback 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.

See Also
Configuration#addInputStream
setMappingResourcesback 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.

See Also
setMappingLocations, Configuration#addResource
setMetadataSourcesback to summary
public void setMetadataSources(MetadataSources metadataSources)

Specify a Hibernate MetadataSources service to use (e.g. reusing an existing one), potentially populated with a custom Hibernate bootstrap org.hibernate.service.ServiceRegistry as well.

Since
4.3
See Also
MetadataSources#MetadataSources(ServiceRegistry), BootstrapServiceRegistryBuilder#build()
setMultiTenantConnectionProviderback to summary
public void setMultiTenantConnectionProvider(MultiTenantConnectionProvider multiTenantConnectionProvider)

Set a MultiTenantConnectionProvider to be passed on to the SessionFactory.

Since
4.3
See Also
LocalSessionFactoryBuilder#setMultiTenantConnectionProvider
setPackagesToScanback 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 (org.springframework.context.annotation.ClassPathBeanDefinitionScanner).

setPhysicalNamingStrategyback to summary
public void setPhysicalNamingStrategy(PhysicalNamingStrategy physicalNamingStrategy)

Set a Hibernate 5 PhysicalNamingStrategy for the SessionFactory.

See Also
Configuration#setPhysicalNamingStrategy
setResourceLoaderback to summary
public void setResourceLoader(ResourceLoader resourceLoader)

Implements org.springframework.context.ResourceLoaderAware.setResourceLoader.

Specify a Spring ResourceLoader to use for Hibernate metadata.

Parameters
resourceLoader:ResourceLoader

the ResourceLoader to use (never null)

Annotations
@Override