类 LocalSessionFactoryBuilder
- java.lang.Object
- org.hibernate.cfg.Configuration
- org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
- 所有已实现的接口:
Serializable
public class LocalSessionFactoryBuilder extends Configuration
A Spring-provided extension of the standard HibernateConfigurationclass, addingSpringSessionContextas a default and providing convenient ways to specify a DataSource and an application class loader.This is designed for programmatic use, e.g. in
@Beanfactory methods. Consider usingLocalSessionFactoryBeanfor XML bean definition files.Requires Hibernate 4.0 or higher. As of Spring 4.0, it is compatible with (the quite refactored) Hibernate 4.3 as well. We recommend using the latest Hibernate 4.2.x or 4.3.x version, depending on whether you need to remain JPA 2.0 compatible at runtime (Hibernate 4.2) or can upgrade to JPA 2.1 (Hibernate 4.3).
NOTE: To set up Hibernate 4 for Spring-driven JTA transactions, make sure to either use the
setJtaTransactionManager(java.lang.Object)method or to set the "hibernate.transaction.factory_class" property toCMTTransactionFactory. Otherwise, Hibernate's smart flushing mechanism won't work properly.- 从以下版本开始:
- 3.1
- 作者:
- Juergen Hoeller
- 另请参阅:
LocalSessionFactoryBean, 序列化表格
嵌套类概要
从类继承的嵌套类/接口 org.hibernate.cfg.Configuration
Configuration.MappingsImpl, Configuration.MetadataSourceQueue
字段概要
从类继承的字段 org.hibernate.cfg.Configuration
ARTEFACT_PROCESSING_ORDER, auxiliaryDatabaseObjects, classes, collections, columnNameBindingPerTable, DEFAULT_ARTEFACT_PROCESSING_ORDER, DEFAULT_CACHE_CONCURRENCY_STRATEGY, extendsQueue, fetchProfiles, filterDefinitions, imports, metadataSourceQueue, namedEntityGraphMap, namedProcedureCallMap, namedQueries, namedSqlQueries, propertyReferences, secondPasses, settingsFactory, sqlFunctions, sqlResultSetMappings, tableNameBinding, tables, typeDefs, USE_NEW_ID_GENERATOR_MAPPINGS, xmlHelper
构造器概要
构造器 构造器 说明 LocalSessionFactoryBuilder(DataSource dataSource)Create a new LocalSessionFactoryBuilder for the given DataSource.LocalSessionFactoryBuilder(DataSource dataSource, ClassLoader classLoader)Create a new LocalSessionFactoryBuilder for the given DataSource.LocalSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader)Create a new LocalSessionFactoryBuilder for the given DataSource.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 LocalSessionFactoryBuilderaddAnnotatedClasses(Class<?>... annotatedClasses)Add the given annotated classes in a batch.LocalSessionFactoryBuilderaddPackages(String... annotatedPackages)Add the given annotated packages in a batch.SessionFactorybuildSessionFactory()Build theSessionFactory.SettingsbuildSettings(Properties props, ServiceRegistry serviceRegistry)LocalSessionFactoryBuilderscanPackages(String... packagesToScan)Perform Spring-based scanning for entity classes, registering them as annotated classes with thisConfiguration.LocalSessionFactoryBuildersetCacheRegionFactory(RegionFactory cacheRegionFactory)Set the Hibernate RegionFactory to use for the SessionFactory.LocalSessionFactoryBuildersetCurrentTenantIdentifierResolver(Object currentTenantIdentifierResolver)Set a Hibernate 4.1/4.2/4.3CurrentTenantIdentifierResolverto be passed on to the SessionFactory: as an instance, a Class, or a String class name.LocalSessionFactoryBuildersetEntityTypeFilters(TypeFilter... entityTypeFilters)Specify custom type filters for Spring-based scanning for entity classes.LocalSessionFactoryBuildersetJtaTransactionManager(Object jtaTransactionManager)Set the SpringJtaTransactionManageror the JTATransactionManagerto be used with Hibernate, if any.LocalSessionFactoryBuildersetMultiTenantConnectionProvider(Object multiTenantConnectionProvider)Set a Hibernate 4.1/4.2/4.3MultiTenantConnectionProviderto be passed on to the SessionFactory: as an instance, a Class, or a String class name.从类继承的方法 org.hibernate.cfg.Configuration
add, addAnnotatedClass, addAttributeConverter, addAttributeConverter, addAttributeConverter, addAttributeConverter, addAttributeConverter, addAuxiliaryDatabaseObject, addCacheableFile, addCacheableFile, addCacheableFileStrictly, addClass, addDirectory, addDocument, addFetchProfile, addFile, addFile, addFilterDefinition, addInputStream, addJar, addPackage, addProperties, addResource, addResource, addSqlFunction, addURL, addXML, buildMapping, buildMappings, buildSessionFactory, buildSettings, configure, configure, configure, configure, configure, createMappings, doConfigure, doConfigure, findPossibleExtends, generateDropSchemaScript, generateSchemaCreationScript, generateSchemaUpdateScript, generateSchemaUpdateScriptList, getClassMapping, getClassMappings, getCollectionMapping, getCollectionMappings, getConfigurationInputStream, getCurrentTenantIdentifierResolver, getEntityNotFoundDelegate, getEntityResolver, getEntityTuplizerFactory, getFilterDefinitions, getIdentifierGeneratorFactory, getImports, getInterceptor, getJaccPermissionDeclarations, getMappedSuperclassMappings, getMappedSuperclassMappingsCopy, getNamedEntityGraphs, getNamedProcedureCallMap, getNamedQueries, getNamedSQLQueries, getNamingStrategy, getNamingStrategyDelegator, getProperties, getProperty, getReflectionManager, getSessionFactoryObserver, getSqlFunctions, getSqlResultSetMappings, getTableMappings, getTypeResolver, iterateFetchProfiles, iterateGenerators, mergeProperties, registerTypeContributor, registerTypeOverride, registerTypeOverride, registerTypeOverride, reset, secondPassCompile, secondPassCompileForeignKeys, setCacheConcurrencyStrategy, setCacheConcurrencyStrategy, setCacheConcurrencyStrategy, setCollectionCacheConcurrencyStrategy, setCollectionCacheConcurrencyStrategy, setCurrentTenantIdentifierResolver, setEntityNotFoundDelegate, setEntityResolver, setInterceptor, setNamingStrategy, setNamingStrategyDelegator, setPrecedence, setProperties, setProperty, setSessionFactoryObserver, validateSchema
构造器详细资料
LocalSessionFactoryBuilder
public LocalSessionFactoryBuilder(DataSource dataSource)
Create a new LocalSessionFactoryBuilder for the given DataSource.- 参数:
dataSource- the JDBC DataSource that the resulting Hibernate SessionFactory should be using (may benull)
LocalSessionFactoryBuilder
public LocalSessionFactoryBuilder(DataSource dataSource, ClassLoader classLoader)
Create a new LocalSessionFactoryBuilder for the given DataSource.- 参数:
dataSource- the JDBC DataSource that the resulting Hibernate SessionFactory should be using (may benull)classLoader- the ClassLoader to load application classes from
LocalSessionFactoryBuilder
public LocalSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader)
Create a new LocalSessionFactoryBuilder for the given DataSource.- 参数:
dataSource- the JDBC DataSource that the resulting Hibernate SessionFactory should be using (may benull)resourceLoader- the ResourceLoader to load application classes from
方法详细资料
setJtaTransactionManager
public LocalSessionFactoryBuilder setJtaTransactionManager(Object jtaTransactionManager)
Set the SpringJtaTransactionManageror the JTATransactionManagerto be used with Hibernate, if any. Allows for using a Spring-managed transaction manager for Hibernate 4's session and cache synchronization, with the "hibernate.transaction.jta.platform" automatically set to it. Also sets "hibernate.transaction.factory_class" toCMTTransactionFactory, instructing Hibernate to interact with externally managed transactions.A passed-in Spring
JtaTransactionManagerneeds to contain a JTATransactionManagerreference to be usable here, except for the WebSphere case where we'll automatically setWebSphereExtendedJtaPlatformaccordingly.Note: If this is set, the Hibernate settings should not contain a JTA platform setting to avoid meaningless double configuration.
setMultiTenantConnectionProvider
public LocalSessionFactoryBuilder setMultiTenantConnectionProvider(Object multiTenantConnectionProvider)
Set a Hibernate 4.1/4.2/4.3MultiTenantConnectionProviderto be passed on to the SessionFactory: as an instance, a Class, or a String class name.Note that the package location of the
MultiTenantConnectionProviderinterface changed between Hibernate 4.2 and 4.3. This method accepts both variants.- 从以下版本开始:
- 4.0
- 另请参阅:
AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER
setCurrentTenantIdentifierResolver
public LocalSessionFactoryBuilder setCurrentTenantIdentifierResolver(Object currentTenantIdentifierResolver)
Set a Hibernate 4.1/4.2/4.3CurrentTenantIdentifierResolverto be passed on to the SessionFactory: as an instance, a Class, or a String class name.- 从以下版本开始:
- 4.0
- 另请参阅:
AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER
setCacheRegionFactory
public LocalSessionFactoryBuilder 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.
- 从以下版本开始:
- 4.0
- 另请参阅:
RegionFactory
setEntityTypeFilters
public LocalSessionFactoryBuilder 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
@javax.persistence.Entity,@javax.persistence.Embeddableor@javax.persistence.MappedSuperclass.- 从以下版本开始:
- 4.1
- 另请参阅:
scanPackages(java.lang.String...)
addAnnotatedClasses
public LocalSessionFactoryBuilder addAnnotatedClasses(Class<?>... annotatedClasses)
Add the given annotated classes in a batch.
addPackages
public LocalSessionFactoryBuilder addPackages(String... annotatedPackages)
Add the given annotated packages in a batch.
scanPackages
public LocalSessionFactoryBuilder scanPackages(String... packagesToScan) throws HibernateException
Perform Spring-based scanning for entity classes, registering them as annotated classes with thisConfiguration.- 参数:
packagesToScan- one or more Java package names- 抛出:
HibernateException- if scanning fails for any reason
buildSettings
public Settings buildSettings(Properties props, ServiceRegistry serviceRegistry) throws HibernateException
- 覆盖:
buildSettings在类中Configuration- 抛出:
HibernateException
buildSessionFactory
public SessionFactory buildSessionFactory() throws HibernateException
Build theSessionFactory.