类 HibernateAccessor
- java.lang.Object
- org.springframework.orm.hibernate3.HibernateAccessor
- 所有已实现的接口:
Aware
,BeanFactoryAware
,InitializingBean
@Deprecated public abstract class HibernateAccessor extends Object implements InitializingBean, BeanFactoryAware
已过时。as of Spring 4.3, in favor of Hibernate 4.x/5.xBase class forHibernateTemplate
andHibernateInterceptor
, defining common properties such as SessionFactory and flushing behavior.Not intended to be used directly. See
HibernateTemplate
andHibernateInterceptor
.- 从以下版本开始:
- 1.2
- 作者:
- Juergen Hoeller
- 另请参阅:
HibernateTemplate
,HibernateInterceptor
,setFlushMode(int)
字段概要
字段 修饰符和类型 字段 说明 static int
FLUSH_ALWAYS
已过时。Flushing before every query statement is rarely necessary.static int
FLUSH_AUTO
已过时。Automatic flushing is the default mode for a Hibernate Session.static int
FLUSH_COMMIT
已过时。Flushing at commit only is intended for units of work where no intermediate flushing is desired, not even for find operations that might involve already modified instances.static int
FLUSH_EAGER
已过时。Eager flushing leads to immediate synchronization with the database, even if in a transaction.static int
FLUSH_NEVER
已过时。Never flush is a good strategy for read-only units of work.protected Log
logger
已过时。Logger available to subclasses
构造器概要
构造器 构造器 说明 HibernateAccessor()
已过时。
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
已过时。Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.protected FlushMode
applyFlushMode(Session session, boolean existingTransaction)
已过时。Apply the flush mode that's been specified for this accessor to the given Session.DataAccessException
convertHibernateAccessException(HibernateException ex)
已过时。Convert the given HibernateException to an appropriate exception from theorg.springframework.dao
hierarchy.protected DataAccessException
convertJdbcAccessException(SQLException ex)
已过时。Convert the given SQLException to an appropriate exception from theorg.springframework.dao
hierarchy.protected DataAccessException
convertJdbcAccessException(JDBCException ex, SQLExceptionTranslator translator)
已过时。Convert the given Hibernate JDBCException to an appropriate exception from theorg.springframework.dao
hierarchy, using the given SQLExceptionTranslator.protected void
disableFilters(Session session)
已过时。Disable the specified filters on the given Session.protected void
enableFilters(Session session)
已过时。Enable the specified filters on the given Session.protected void
flushIfNecessary(Session session, boolean existingTransaction)
已过时。Flush the given Hibernate Session if necessary.protected SQLExceptionTranslator
getDefaultJdbcExceptionTranslator()
已过时。Obtain a default SQLExceptionTranslator, lazily creating it if necessary.Interceptor
getEntityInterceptor()
已过时。Return the current Hibernate entity interceptor, ornull
if none.String[]
getFilterNames()
已过时。Return the names of Hibernate filters to be activated, if any.int
getFlushMode()
已过时。Return if a flush should be forced after executing the callback code.SQLExceptionTranslator
getJdbcExceptionTranslator()
已过时。Return the JDBC exception translator for this instance, if any.SessionFactory
getSessionFactory()
已过时。Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.void
setBeanFactory(BeanFactory beanFactory)
已过时。The bean factory just needs to be known for resolving entity interceptor bean names.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.void
setEntityInterceptorBeanName(String entityInterceptorBeanName)
已过时。Set the bean name of a Hibernate entity interceptor that allows to inspect and change property values before writing to and reading from the database.void
setFilterName(String filter)
已过时。Set the name of a Hibernate filter to be activated for all Sessions that this accessor works with.void
setFilterNames(String... filterNames)
已过时。Set one or more names of Hibernate filters to be activated for all Sessions that this accessor works with.void
setFlushMode(int flushMode)
已过时。Set the flush behavior to one of the constants in this class.void
setFlushModeName(String constantName)
已过时。Set the flush behavior by the name of the respective constant in this class, e.g.void
setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
已过时。Set the JDBC exception translator for this instance.void
setSessionFactory(SessionFactory sessionFactory)
已过时。Set the Hibernate SessionFactory that should be used to create Hibernate Sessions.
字段详细资料
FLUSH_NEVER
public static final int FLUSH_NEVER
已过时。Never flush is a good strategy for read-only units of work. Hibernate will not track and look for changes in this case, avoiding any overhead of modification detection.In case of an existing Session, FLUSH_NEVER will turn the flush mode to NEVER for the scope of the current operation, resetting the previous flush mode afterwards.
- 另请参阅:
setFlushMode(int)
, 常量字段值
FLUSH_AUTO
public static final int FLUSH_AUTO
已过时。Automatic flushing is the default mode for a Hibernate Session. A session will get flushed on transaction commit, and on certain find operations that might involve already modified instances, but not after each unit of work like with eager flushing.In case of an existing Session, FLUSH_AUTO will participate in the existing flush mode, not modifying it for the current operation. This in particular means that this setting will not modify an existing flush mode NEVER, in contrast to FLUSH_EAGER.
- 另请参阅:
setFlushMode(int)
, 常量字段值
FLUSH_EAGER
public static final int FLUSH_EAGER
已过时。Eager flushing leads to immediate synchronization with the database, even if in a transaction. This causes inconsistencies to show up and throw a respective exception immediately, and JDBC access code that participates in the same transaction will see the changes as the database is already aware of them then. But the drawbacks are:- additional communication roundtrips with the database, instead of a single batch at transaction commit;
- the fact that an actual database rollback is needed if the Hibernate transaction rolls back (due to already submitted SQL statements).
In case of an existing Session, FLUSH_EAGER will turn the flush mode to AUTO for the scope of the current operation and issue a flush at the end, resetting the previous flush mode afterwards.
- 另请参阅:
setFlushMode(int)
, 常量字段值
FLUSH_COMMIT
public static final int FLUSH_COMMIT
已过时。Flushing at commit only is intended for units of work where no intermediate flushing is desired, not even for find operations that might involve already modified instances.In case of an existing Session, FLUSH_COMMIT will turn the flush mode to COMMIT for the scope of the current operation, resetting the previous flush mode afterwards. The only exception is an existing flush mode NEVER, which will not be modified through this setting.
- 另请参阅:
setFlushMode(int)
, 常量字段值
FLUSH_ALWAYS
public static final int FLUSH_ALWAYS
已过时。Flushing before every query statement is rarely necessary. It is only available for special needs.In case of an existing Session, FLUSH_ALWAYS will turn the flush mode to ALWAYS for the scope of the current operation, resetting the previous flush mode afterwards.
- 另请参阅:
setFlushMode(int)
, 常量字段值
构造器详细资料
HibernateAccessor
public HibernateAccessor()
已过时。
方法详细资料
setSessionFactory
public void setSessionFactory(SessionFactory sessionFactory)
已过时。Set the Hibernate SessionFactory that should be used to create Hibernate Sessions.
getSessionFactory
public SessionFactory getSessionFactory()
已过时。Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
setEntityInterceptorBeanName
public void setEntityInterceptorBeanName(String entityInterceptorBeanName)
已过时。Set the bean name of 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 transaction manager.Requires the bean factory to be known, to be able to resolve the bean name to an interceptor instance on session creation. Typically used for prototype interceptors, i.e. a new interceptor instance per session.
Can also be used for shared interceptor instances, but it is recommended to set the interceptor reference directly in such a scenario.
- 参数:
entityInterceptorBeanName
- the name of the entity interceptor in the bean factory- 另请参阅:
setBeanFactory(org.springframework.beans.factory.BeanFactory)
,setEntityInterceptor(org.hibernate.Interceptor)
setEntityInterceptor
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 object.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.
getEntityInterceptor
public Interceptor getEntityInterceptor() throws IllegalStateException, BeansException
已过时。Return the current Hibernate entity interceptor, ornull
if none. Resolves an entity interceptor bean name via the bean factory, if necessary.- 抛出:
IllegalStateException
- if bean name specified but no bean factory setBeansException
- if bean name resolution via the bean factory failed- 另请参阅:
setEntityInterceptor(org.hibernate.Interceptor)
,setEntityInterceptorBeanName(java.lang.String)
,setBeanFactory(org.springframework.beans.factory.BeanFactory)
setJdbcExceptionTranslator
public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
已过时。Set the JDBC exception translator for this instance.Applied to any SQLException root cause of a Hibernate JDBCException, overriding Hibernate's default SQLException translation (which is based on Hibernate's Dialect for a specific target database).
- 参数:
jdbcExceptionTranslator
- the exception translator- 另请参阅:
SQLException
,JDBCException
,SQLErrorCodeSQLExceptionTranslator
,SQLStateSQLExceptionTranslator
getJdbcExceptionTranslator
public SQLExceptionTranslator getJdbcExceptionTranslator()
已过时。Return the JDBC exception translator for this instance, if any.
setFlushModeName
public void setFlushModeName(String constantName)
已过时。Set the flush behavior by the name of the respective constant in this class, e.g. "FLUSH_AUTO". Default is "FLUSH_AUTO".- 参数:
constantName
- name of the constant- 另请参阅:
setFlushMode(int)
,FLUSH_AUTO
setFlushMode
public void setFlushMode(int flushMode)
已过时。Set the flush behavior to one of the constants in this class. Default is FLUSH_AUTO.
getFlushMode
public int getFlushMode()
已过时。Return if a flush should be forced after executing the callback code.
setFilterName
public void setFilterName(String filter)
已过时。Set the name of a Hibernate filter to be activated for all Sessions that this accessor works with.This filter will be enabled at the beginning of each operation and correspondingly disabled at the end of the operation. This will work for newly opened Sessions as well as for existing Sessions (for example, within a transaction).
setFilterNames
public void setFilterNames(String... filterNames)
已过时。Set one or more names of Hibernate filters to be activated for all Sessions that this accessor works with.Each of those filters will be enabled at the beginning of each operation and correspondingly disabled at the end of the operation. This will work for newly opened Sessions as well as for existing Sessions (for example, within a transaction).
getFilterNames
public String[] getFilterNames()
已过时。Return the names of Hibernate filters to be activated, if any.
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
已过时。The bean factory just needs to be known for resolving entity interceptor bean names. It does not need to be set for any other mode of operation.- 指定者:
setBeanFactory
在接口中BeanFactoryAware
- 参数:
beanFactory
- owning BeanFactory (nevernull
). The bean can immediately call methods on the factory.- 另请参阅:
setEntityInterceptorBeanName(java.lang.String)
afterPropertiesSet
public void afterPropertiesSet()
已过时。从接口复制的说明:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,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.
- 指定者:
afterPropertiesSet
在接口中InitializingBean
applyFlushMode
protected FlushMode applyFlushMode(Session session, boolean existingTransaction)
已过时。Apply the flush mode that's been specified for this accessor to the given Session.- 参数:
session
- the current Hibernate SessionexistingTransaction
- if executing within an existing transaction- 返回:
- the previous flush mode to restore after the operation, or
null
if none - 另请参阅:
setFlushMode(int)
,Session.setFlushMode(org.hibernate.FlushMode)
flushIfNecessary
protected void flushIfNecessary(Session session, boolean existingTransaction) throws HibernateException
已过时。Flush the given Hibernate Session if necessary.- 参数:
session
- the current Hibernate SessionexistingTransaction
- if executing within an existing transaction- 抛出:
HibernateException
- in case of Hibernate flushing errors
convertHibernateAccessException
public DataAccessException convertHibernateAccessException(HibernateException ex)
已过时。Convert the given HibernateException to an appropriate exception from theorg.springframework.dao
hierarchy.Will automatically apply a specified SQLExceptionTranslator to a Hibernate JDBCException, else rely on Hibernate's default translation.
- 参数:
ex
- HibernateException that occured- 返回:
- a corresponding DataAccessException
- 另请参阅:
SessionFactoryUtils.convertHibernateAccessException(org.hibernate.HibernateException)
,setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
convertJdbcAccessException
protected DataAccessException convertJdbcAccessException(JDBCException ex, SQLExceptionTranslator translator)
已过时。Convert the given Hibernate JDBCException to an appropriate exception from theorg.springframework.dao
hierarchy, using the given SQLExceptionTranslator.- 参数:
ex
- Hibernate JDBCException that occuredtranslator
- the SQLExceptionTranslator to use- 返回:
- a corresponding DataAccessException
convertJdbcAccessException
protected DataAccessException convertJdbcAccessException(SQLException ex)
已过时。Convert the given SQLException to an appropriate exception from theorg.springframework.dao
hierarchy. Can be overridden in subclasses.Note that a direct SQLException can just occur when callback code performs direct JDBC access via
Session.connection()
.- 参数:
ex
- the SQLException- 返回:
- the corresponding DataAccessException instance
- 另请参阅:
setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
getDefaultJdbcExceptionTranslator
protected SQLExceptionTranslator getDefaultJdbcExceptionTranslator()
已过时。Obtain a default SQLExceptionTranslator, lazily creating it if necessary.Creates a default
SQLErrorCodeSQLExceptionTranslator
for the SessionFactory's underlying DataSource.
enableFilters
protected void enableFilters(Session session)
已过时。Enable the specified filters on the given Session.- 参数:
session
- the current Hibernate Session- 另请参阅:
setFilterNames(java.lang.String...)
,Session.enableFilter(String)
disableFilters
protected void disableFilters(Session session)
已过时。Disable the specified filters on the given Session.- 参数:
session
- the current Hibernate Session- 另请参阅:
setFilterNames(java.lang.String...)
,Session.disableFilter(String)