@Deprecated public abstract class HibernateDaoSupport extends DaoSupport
Requires a SessionFactory
to be set, providing a
HibernateTemplate
based on it to
subclasses through the getHibernateTemplate()
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()
and releaseSession(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()
.
setSessionFactory(org.hibernate.SessionFactory)
,
getHibernateTemplate()
,
HibernateTemplate
logger
Constructor and Description |
---|
HibernateDaoSupport()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkDaoConfig()
Deprecated.
Abstract subclasses must override this to check their configuration.
|
protected DataAccessException |
convertHibernateAccessException(HibernateException ex)
Deprecated.
as of Spring 3.2.7, in favor of
HibernateTemplate usage |
protected HibernateTemplate |
createHibernateTemplate(SessionFactory sessionFactory)
Deprecated.
Create a HibernateTemplate for the given SessionFactory.
|
HibernateTemplate |
getHibernateTemplate()
Deprecated.
Return the HibernateTemplate for this DAO,
pre-initialized with the SessionFactory or set explicitly.
|
protected Session |
getSession()
Deprecated.
as of Spring 3.2.7, in favor of
HibernateTemplate usage |
protected Session |
getSession(boolean allowCreate)
Deprecated.
as of Spring 3.2.7, in favor of
HibernateTemplate usage |
SessionFactory |
getSessionFactory()
Deprecated.
Return the Hibernate SessionFactory used by this DAO.
|
protected void |
releaseSession(Session session)
Deprecated.
as of Spring 3.2.7, in favor of
HibernateTemplate usage |
void |
setHibernateTemplate(HibernateTemplate hibernateTemplate)
Deprecated.
Set the HibernateTemplate for this DAO explicitly,
as an alternative to specifying a SessionFactory.
|
void |
setSessionFactory(SessionFactory sessionFactory)
Deprecated.
Set the Hibernate SessionFactory to be used by this DAO.
|
afterPropertiesSet, initDao
public final void setSessionFactory(SessionFactory sessionFactory)
protected HibernateTemplate createHibernateTemplate(SessionFactory sessionFactory)
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 forsetSessionFactory(org.hibernate.SessionFactory)
public final SessionFactory getSessionFactory()
public final void setHibernateTemplate(HibernateTemplate hibernateTemplate)
public final HibernateTemplate getHibernateTemplate()
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 via
new HibernateTemplate(getSessionFactory())
, in which case
you're allowed to customize the settings on the resulting instance.
protected final void checkDaoConfig()
DaoSupport
Implementors should be marked as final
if concrete subclasses
are not supposed to override this template method themselves.
checkDaoConfig
in class DaoSupport
@Deprecated protected final Session getSession() throws DataAccessResourceFailureException, IllegalStateException
HibernateTemplate
usage"allowCreate"
setting of this bean's HibernateTemplate
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.
DataAccessResourceFailureException
- if the Session couldn't be createdIllegalStateException
- if no thread-bound Session found and allowCreate=falseSessionFactoryUtils.getSession(SessionFactory, boolean)
@Deprecated protected final Session getSession(boolean allowCreate) throws DataAccessResourceFailureException, IllegalStateException
HibernateTemplate
usageNote 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.
allowCreate
- if a non-transactional Session should be created when no
transactional Session can be found for the current threadDataAccessResourceFailureException
- if the Session couldn't be createdIllegalStateException
- if no thread-bound Session found and allowCreate=falseSessionFactoryUtils.getSession(SessionFactory, boolean)
@Deprecated protected final DataAccessException convertHibernateAccessException(HibernateException ex)
HibernateTemplate
usageorg.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()
and releaseSession(org.hibernate.Session)
.
ex
- HibernateException that occurredSessionFactoryUtils.convertHibernateAccessException(org.hibernate.HibernateException)
@Deprecated protected final void releaseSession(Session session)
HibernateTemplate
usageTypically used in plain Hibernate code, in combination with
getSession()
and convertHibernateAccessException(org.hibernate.HibernateException)
.
session
- the Session to closeSessionFactoryUtils.releaseSession(org.hibernate.Session, org.hibernate.SessionFactory)