类 HibernateDaoSupport
- java.lang.Object
- org.springframework.dao.support.DaoSupport
- org.springframework.orm.hibernate3.support.HibernateDaoSupport
- 所有已实现的接口:
InitializingBean
@Deprecated public abstract class HibernateDaoSupport extends DaoSupport
已过时。as of Spring 4.3, in favor of Hibernate 4.x/5.xConvenient super class for Hibernate-based data access objects.Requires a
SessionFactory
to be set, providing aHibernateTemplate
based on it to subclasses through thegetHibernateTemplate()
method. Can alternatively be initialized directly with a HibernateTemplate, in order to reuse the latter's settings such as the SessionFactory, exception translator, flush mode, etc.This base class is mainly intended for HibernateTemplate usage but can also be used when working with a Hibernate Session directly, for example when relying on transactional Sessions. Convenience
getSession()
andreleaseSession(org.hibernate.Session)
methods are provided for that usage style.This class will create its own HibernateTemplate instance if a SessionFactory is passed in. The "allowCreate" flag on that HibernateTemplate will be "true" by default. A custom HibernateTemplate instance can be used through overriding
createHibernateTemplate(org.hibernate.SessionFactory)
.NOTE: As of Hibernate 3.0.1, transactional Hibernate access code can also be coded in plain Hibernate style. Hence, for newly started projects, consider adopting the standard Hibernate3 style of coding data access objects instead, based on
SessionFactory.getCurrentSession()
.- 从以下版本开始:
- 1.2
- 作者:
- Juergen Hoeller
- 另请参阅:
setSessionFactory(org.hibernate.SessionFactory)
,getHibernateTemplate()
,HibernateTemplate
字段概要
从类继承的字段 org.springframework.dao.support.DaoSupport
logger
构造器概要
构造器 构造器 说明 HibernateDaoSupport()
已过时。
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 protected void
checkDaoConfig()
已过时。Abstract subclasses must override this to check their configuration.protected DataAccessException
convertHibernateAccessException(HibernateException ex)
已过时。as of Spring 3.2.7, in favor ofHibernateTemplate
usageprotected HibernateTemplate
createHibernateTemplate(SessionFactory sessionFactory)
已过时。Create a HibernateTemplate for the given SessionFactory.HibernateTemplate
getHibernateTemplate()
已过时。Return the HibernateTemplate for this DAO, pre-initialized with the SessionFactory or set explicitly.protected Session
getSession()
已过时。as of Spring 3.2.7, in favor ofHibernateTemplate
usageprotected Session
getSession(boolean allowCreate)
已过时。as of Spring 3.2.7, in favor ofHibernateTemplate
usageSessionFactory
getSessionFactory()
已过时。Return the Hibernate SessionFactory used by this DAO.protected void
releaseSession(Session session)
已过时。as of Spring 3.2.7, in favor ofHibernateTemplate
usagevoid
setHibernateTemplate(HibernateTemplate hibernateTemplate)
已过时。Set the HibernateTemplate for this DAO explicitly, as an alternative to specifying a SessionFactory.void
setSessionFactory(SessionFactory sessionFactory)
已过时。Set the Hibernate SessionFactory to be used by this DAO.从类继承的方法 org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
构造器详细资料
HibernateDaoSupport
public HibernateDaoSupport()
已过时。
方法详细资料
setSessionFactory
public final void setSessionFactory(SessionFactory sessionFactory)
已过时。Set the Hibernate SessionFactory to be used by this DAO. Will automatically create a HibernateTemplate for the given SessionFactory.
createHibernateTemplate
protected HibernateTemplate createHibernateTemplate(SessionFactory sessionFactory)
已过时。Create a HibernateTemplate for the given SessionFactory. Only invoked if populating the DAO with a SessionFactory reference!Can be overridden in subclasses to provide a HibernateTemplate instance with different configuration, or a custom HibernateTemplate subclass.
- 参数:
sessionFactory
- the Hibernate SessionFactory to create a HibernateTemplate for- 返回:
- the new HibernateTemplate instance
- 另请参阅:
setSessionFactory(org.hibernate.SessionFactory)
getSessionFactory
public final SessionFactory getSessionFactory()
已过时。Return the Hibernate SessionFactory used by this DAO.
setHibernateTemplate
public final void setHibernateTemplate(HibernateTemplate hibernateTemplate)
已过时。Set the HibernateTemplate for this DAO explicitly, as an alternative to specifying a SessionFactory.
getHibernateTemplate
public final HibernateTemplate getHibernateTemplate()
已过时。Return the HibernateTemplate for this DAO, pre-initialized with the SessionFactory or set explicitly.Note: The returned HibernateTemplate is a shared instance. You may introspect its configuration, but not modify the configuration (other than from within an
DaoSupport.initDao()
implementation). Consider creating a custom HibernateTemplate instance vianew HibernateTemplate(getSessionFactory())
, in which case you're allowed to customize the settings on the resulting instance.
checkDaoConfig
protected final void checkDaoConfig()
已过时。从类复制的说明:DaoSupport
Abstract subclasses must override this to check their configuration.Implementors should be marked as
final
if concrete subclasses are not supposed to override this template method themselves.- 指定者:
checkDaoConfig
在类中DaoSupport
getSession
@Deprecated protected final Session getSession() throws DataAccessResourceFailureException, IllegalStateException
已过时。as of Spring 3.2.7, in favor ofHibernateTemplate
usageObtain a Hibernate Session, either from the current transaction or a new one. The latter is only allowed if the"allowCreate"
setting of this bean'sHibernateTemplate
is "true".Note that this is not meant to be invoked from HibernateTemplate code but rather just in plain Hibernate code. Either rely on a thread-bound Session or use it in combination with
releaseSession(org.hibernate.Session)
.In general, it is recommended to use HibernateTemplate, either with the provided convenience operations or with a custom HibernateCallback that provides you with a Session to work on. HibernateTemplate will care for all resource management and for proper exception conversion.
- 返回:
- the Hibernate Session
- 抛出:
DataAccessResourceFailureException
- if the Session couldn't be createdIllegalStateException
- if no thread-bound Session found and allowCreate=false- 另请参阅:
SessionFactoryUtils.getSession(SessionFactory, boolean)
getSession
@Deprecated protected final Session getSession(boolean allowCreate) throws DataAccessResourceFailureException, IllegalStateException
已过时。as of Spring 3.2.7, in favor ofHibernateTemplate
usageObtain a Hibernate Session, either from the current transaction or a new one. The latter is only allowed if "allowCreate" is true.Note that this is not meant to be invoked from HibernateTemplate code but rather just in plain Hibernate code. Either rely on a thread-bound Session or use it in combination with
releaseSession(org.hibernate.Session)
.In general, it is recommended to use
HibernateTemplate
, either with the provided convenience operations or with a customHibernateCallback
that provides you with a Session to work on. HibernateTemplate will care for all resource management and for proper exception conversion.- 参数:
allowCreate
- if a non-transactional Session should be created when no transactional Session can be found for the current thread- 返回:
- the Hibernate Session
- 抛出:
DataAccessResourceFailureException
- if the Session couldn't be createdIllegalStateException
- if no thread-bound Session found and allowCreate=false- 另请参阅:
SessionFactoryUtils.getSession(SessionFactory, boolean)
convertHibernateAccessException
@Deprecated protected final DataAccessException convertHibernateAccessException(HibernateException ex)
已过时。as of Spring 3.2.7, in favor ofHibernateTemplate
usageConvert the given HibernateException to an appropriate exception from theorg.springframework.dao
hierarchy. Will automatically detect wrapped SQLExceptions and convert them accordingly.Delegates to the
HibernateAccessor.convertHibernateAccessException(org.hibernate.HibernateException)
method of this DAO's HibernateTemplate.Typically used in plain Hibernate code, in combination with
getSession()
andreleaseSession(org.hibernate.Session)
.- 参数:
ex
- HibernateException that occurred- 返回:
- the corresponding DataAccessException instance
- 另请参阅:
SessionFactoryUtils.convertHibernateAccessException(org.hibernate.HibernateException)
releaseSession
@Deprecated protected final void releaseSession(Session session)
已过时。as of Spring 3.2.7, in favor ofHibernateTemplate
usageClose the given Hibernate Session, created via this DAO's SessionFactory, if it isn't bound to the thread (i.e. isn't a transactional Session).Typically used in plain Hibernate code, in combination with
getSession()
andconvertHibernateAccessException(org.hibernate.HibernateException)
.- 参数:
session
- the Session to close- 另请参阅:
SessionFactoryUtils.releaseSession(org.hibernate.Session, org.hibernate.SessionFactory)