📄 localsessionfactorybean.java
字号:
}
}
/**
* 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.
* <p>Can be used to add to mappings from a Hibernate XML config file,
* or to specify all mappings locally.
* @see org.hibernate.cfg.Configuration#addInputStream
*/
public void setMappingLocations(Resource[] mappingLocations) {
this.mappingLocations = mappingLocations;
}
/**
* 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.
* <p>Can be used to add to mappings from a Hibernate XML config file,
* or to specify all mappings locally.
* @see org.hibernate.cfg.Configuration#addCacheableFile(java.io.File)
*/
public void setCacheableMappingLocations(Resource[] cacheableMappingLocations) {
this.cacheableMappingLocations = cacheableMappingLocations;
}
/**
* Set locations of jar files that contain Hibernate mapping resources,
* like "WEB-INF/lib/example.hbm.jar".
* <p>Can be used to add to mappings from a Hibernate XML config file,
* or to specify all mappings locally.
* @see org.hibernate.cfg.Configuration#addJar(java.io.File)
*/
public void setMappingJarLocations(Resource[] mappingJarLocations) {
this.mappingJarLocations = mappingJarLocations;
}
/**
* Set locations of directories that contain Hibernate mapping resources,
* like "WEB-INF/mappings".
* <p>Can be used to add to mappings from a Hibernate XML config file,
* or to specify all mappings locally.
* @see org.hibernate.cfg.Configuration#addDirectory(java.io.File)
*/
public void setMappingDirectoryLocations(Resource[] mappingDirectoryLocations) {
this.mappingDirectoryLocations = mappingDirectoryLocations;
}
/**
* Set Hibernate properties, such as "hibernate.dialect".
* <p>Can be used to override values in a Hibernate XML config file,
* or to specify all necessary properties locally.
* <p>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 #setDataSource
*/
public void setHibernateProperties(Properties hibernateProperties) {
this.hibernateProperties = hibernateProperties;
}
/**
* Return the Hibernate properties, if any. Mainly available for
* configuration through property paths that specify individual keys.
*/
public Properties getHibernateProperties() {
if (this.hibernateProperties == null) {
this.hibernateProperties = new Properties();
}
return this.hibernateProperties;
}
/**
* Set the DataSource to be used by the SessionFactory.
* If set, this will override corresponding settings in Hibernate properties.
* <p>If this is set, the Hibernate settings should not define
* a connection provider to avoid meaningless double configuration.
* <p>If using HibernateTransactionManager as transaction strategy, consider
* proxying your target DataSource with a LazyConnectionDataSourceProxy.
* This defers fetching of an actual JDBC Connection until the first JDBC
* Statement gets executed, even within JDBC transactions (as performed by
* HibernateTransactionManager). Such lazy fetching is particularly beneficial
* for read-only operations, in particular if the chances of resolving the
* result in the second-level cache are high.
* <p>As JTA and transactional JNDI DataSources already provide lazy enlistment
* of JDBC Connections, LazyConnectionDataSourceProxy does not add value with
* JTA (i.e. Spring's JtaTransactionManager) as transaction strategy.
* @see #setUseTransactionAwareDataSource
* @see LocalDataSourceConnectionProvider
* @see HibernateTransactionManager
* @see org.springframework.transaction.jta.JtaTransactionManager
* @see org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy
*/
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
/**
* Set whether to use a transaction-aware DataSource for the SessionFactory,
* i.e. whether to automatically wrap the passed-in DataSource with Spring's
* TransactionAwareDataSourceProxy.
* <p>Default is "false": LocalSessionFactoryBean is usually used with Spring's
* HibernateTransactionManager or JtaTransactionManager, both of which work nicely
* on a plain JDBC DataSource. Hibernate Sessions and their JDBC Connections are
* fully managed by the Hibernate/JTA transaction infrastructure in such a scenario.
* <p>If you switch this flag to "true", Spring's Hibernate access will be able to
* <i>participate in JDBC-based transactions managed outside of Hibernate</i>
* (for example, by Spring's DataSourceTransactionManager). This can be convenient
* if you need a different local transaction strategy for another O/R mapping tool,
* for example, but still want Hibernate access to join into those transactions.
* <p>A further benefit of this option is that <i>plain Sessions opened directly
* via the SessionFactory</i>, outside of Spring's Hibernate support, will still
* participate in active Spring-managed transactions. However, consider using
* Hibernate's <code>getCurrentSession()</code> method instead (see javadoc of
* "exposeTransactionAwareSessionFactory" property).
* <p>As a further effect, using a transaction-aware DataSource will <i>apply
* remaining transaction timeouts to all created JDBC Statements</i>. This means
* that all operations performed by the SessionFactory will automatically
* participate in Spring-managed transaction timeouts, not just queries.
* This adds value even for HibernateTransactionManager, but only on Hibernate 3.0,
* as there is a direct transaction timeout facility in Hibernate 3.1.
* <p><b>WARNING:</b> When using a transaction-aware JDBC DataSource in combination
* with OpenSessionInViewFilter/Interceptor, whether participating in JTA or
* external JDBC-based transactions, it is strongly recommended to set Hibernate's
* Connection release mode to "after_transaction" or "after_statement", which
* guarantees proper Connection handling in such a scenario. In contrast to that,
* HibernateTransactionManager generally requires release mode "on_close".
* <p>Note: If you want to use Hibernate's Connection release mode "after_statement"
* with a DataSource specified on this LocalSessionFactoryBean (for example, a
* JTA-aware DataSource fetched from JNDI), switch this setting to "true".
* Else, the ConnectionProvider used underneath will vote against aggressive
* release and thus silently switch to release mode "after_transaction".
* @see #setDataSource
* @see #setExposeTransactionAwareSessionFactory
* @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
* @see org.springframework.jdbc.datasource.DataSourceTransactionManager
* @see org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
* @see org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor
* @see HibernateTransactionManager
* @see org.springframework.transaction.jta.JtaTransactionManager
*/
public void setUseTransactionAwareDataSource(boolean useTransactionAwareDataSource) {
this.useTransactionAwareDataSource = useTransactionAwareDataSource;
}
/**
* Set whether to expose a transaction-aware proxy for the SessionFactory,
* returning the Session that's associated with the current Spring-managed
* transaction on <code>getCurrentSession()</code>, if any.
* <p>Default is "true", letting data access code work with the plain
* Hibernate SessionFactory and its <code>getCurrentSession()</code> method,
* while still being able to participate in current Spring-managed transactions:
* with any transaction management strategy, either local or JTA / EJB CMT,
* and any transaction synchronization mechanism, either Spring or JTA.
* Furthermore, <code>getCurrentSession()</code> will also seamlessly work with
* a request-scoped Session managed by OpenSessionInViewFilter/Interceptor.
* <p>Turn this flag off to expose the plain Hibernate SessionFactory with
* Hibernate's default <code>getCurrentSession()</code> behavior, which only
* supports plain JTA synchronization through the JTA TransactionManager.
* <p><b>NOTE:</b> The <code>SessionFactory.getCurrentSession</code> method
* is only available in Hibernate 3.0.1 and later. Before its introduction,
* DAOs coded against the plain Hibernate API had to manually open and close
* Sessions and care for transaction/request scoping.
* @see org.hibernate.SessionFactory#getCurrentSession()
* @see org.springframework.transaction.jta.JtaTransactionManager
* @see HibernateTransactionManager
* @see org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
* @see org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor
*/
public void setExposeTransactionAwareSessionFactory(boolean exposeTransactionAwareSessionFactory) {
this.exposeTransactionAwareSessionFactory = exposeTransactionAwareSessionFactory;
}
/**
* Set the JTA TransactionManager to be used for Hibernate's
* TransactionManagerLookup. If set, this will override corresponding
* settings in Hibernate properties. Allows to use a Spring-managed
* JTA TransactionManager for Hibernate's cache synchronization.
* <p>Note: If this is set, the Hibernate settings should not define a
* transaction manager lookup to avoid meaningless double configuration.
* @see LocalTransactionManagerLookup
*/
public void setJtaTransactionManager(TransactionManager jtaTransactionManager) {
this.jtaTransactionManager = jtaTransactionManager;
}
/**
* Set the LobHandler to be used by the SessionFactory.
* Will be exposed at config time for UserType implementations.
* @see #getConfigTimeLobHandler
* @see org.hibernate.usertype.UserType
* @see org.springframework.orm.hibernate3.support.ClobStringType
* @see org.springframework.orm.hibernate3.support.BlobByteArrayType
* @see org.springframework.orm.hibernate3.support.BlobSerializableType
*/
public void setLobHandler(LobHandler lobHandler) {
this.lobHandler = lobHandler;
}
/**
* 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.
* <p>Such an interceptor can either be set at the SessionFactory level, i.e. on
* LocalSessionFactoryBean, or at the Session level, i.e. on HibernateTemplate,
* HibernateInterceptor, and HibernateTransactionManager. It's preferable to set
* it on LocalSessionFactoryBean or HibernateTransactionManager to avoid repeated
* configuration and guarantee consistent behavior in transactions.
* @see HibernateTemplate#setEntityInterceptor
* @see HibernateInterceptor#setEntityInterceptor
* @see HibernateTransactionManager#setEntityInterceptor
* @see org.hibernate.cfg.Configuration#setInterceptor
*/
public void setEntityInterceptor(Interceptor entityInterceptor) {
this.entityInterceptor = entityInterceptor;
}
/**
* Set a Hibernate NamingStrategy for the SessionFactory, determining the
* physical column and table names given the info in the mapping document.
* @see org.hibernate.cfg.Configuration#setNamingStrategy
*/
public void setNamingStrategy(NamingStrategy namingStrategy) {
this.namingStrategy = namingStrategy;
}
/**
* Specify the cache strategies for entities (persistent classes or named entities).
* This configuration setting corresponds to the <class-cache> entry
* in the "hibernate.cfg.xml" configuration format.
* <p>For example:
* <pre>
* <property name="entityCacheStrategies">
* <props>
* <prop key="com.mycompany.Customer">read-write</prop>
* <prop key="com.mycompany.Product">read-only,myRegion</prop>
* </props>
* </property></pre>
* @param entityCacheStrategies properties that define entity cache strategies,
* with class names as keys and cache concurrency strategies as values
* @see org.hibernate.cfg.Configuration#setCacheConcurrencyStrategy(String, String)
*/
public void setEntityCacheStrategies(Properties entityCacheStrategies) {
this.entityCacheStrategies = entityCacheStrategies;
}
/**
* Specify the cache strategies for persistent collections (with specific roles).
* This configuration setting corresponds to the <collection-cache> entry
* in the "hibernate.cfg.xml" configuration format.
* <p>For example:
* <pre>
* <property name="collectionCacheStrategies">
* <props>
* <prop key="com.mycompany.Order.items">read-write</prop>
* <prop key="com.mycompany.Product.categories">read-only,myRegion</prop>
* </props>
* </property></pre>
* @param collectionCacheStrategies properties that define collection cache strategies,
* with collection roles as keys and cache concurrency strategies as values
* @see org.hibernate.cfg.Configuration#setCollectionCacheConcurrencyStrategy(String, String)
*/
public void setCollectionCacheStrategies(Properties collectionCacheStrategies) {
this.collectionCacheStrategies = collectionCacheStrategies;
}
/**
* Specify the Hibernate type definitions to register with the SessionFactory,
* as Spring TypeDefinitionBean instances. This is an alternative to specifying
* <<typedef> elements in Hibernate mapping files.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -