|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.orm.hibernate.support.HibernateDaoSupport
Convenient super class for Hibernate data access objects.
Requires a SessionFactory to be set, providing a HibernateTemplate based on it to subclasses. Can alternatively be initialized directly via a HibernateTemplate, to reuse the latter's settings like SessionFactory, flush mode, exception translator, etc.
This base class is mainly intended for HibernateTemplate usage but can also be used when working with SessionFactoryUtils directly, e.g. in combination with HibernateInterceptor-managed Sessions. Convenience getSession and closeSessionIfNecessary methods are provided for that usage.
setSessionFactory(net.sf.hibernate.SessionFactory)
,
setHibernateTemplate(org.springframework.orm.hibernate.HibernateTemplate)
,
HibernateTemplate
,
HibernateInterceptor
Field Summary | |
protected org.apache.commons.logging.Log |
logger
|
Constructor Summary | |
HibernateDaoSupport()
|
Method Summary | |
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
protected void |
closeSessionIfNecessary(net.sf.hibernate.Session session)
Close the given Hibernate Session if necessary, created via this bean's SessionFactory, if it isn't bound to the thread. |
protected DataAccessException |
convertHibernateAccessException(net.sf.hibernate.HibernateException ex)
Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy. |
protected HibernateTemplate |
getHibernateTemplate()
Return the HibernateTemplate for this DAO, pre-initialized with the SessionFactory or set explicitly. |
protected net.sf.hibernate.Session |
getSession()
Get a Hibernate Session, either from the current transaction or a new one. |
protected net.sf.hibernate.Session |
getSession(boolean allowCreate)
Get a Hibernate Session, either from the current transaction or a new one. |
protected net.sf.hibernate.SessionFactory |
getSessionFactory()
Return the Hibernate SessionFactory used by this DAO. |
protected void |
initDao()
Subclasses can override this for custom initialization behavior. |
void |
setHibernateTemplate(HibernateTemplate hibernateTemplate)
Set the HibernateTemplate for this DAO explicitly, as an alternative to specifying a SessionFactory. |
void |
setSessionFactory(net.sf.hibernate.SessionFactory sessionFactory)
Set the Hibernate SessionFactory to be used by this DAO. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final org.apache.commons.logging.Log logger
Constructor Detail |
public HibernateDaoSupport()
Method Detail |
public final void setSessionFactory(net.sf.hibernate.SessionFactory sessionFactory)
protected final net.sf.hibernate.SessionFactory getSessionFactory()
public final void setHibernateTemplate(HibernateTemplate hibernateTemplate)
protected final HibernateTemplate getHibernateTemplate()
public final void afterPropertiesSet() throws java.lang.Exception
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
java.lang.Exception
- in the event of misconfiguration (such
as failure to set an essential property) or if initialization fails.protected void initDao() throws java.lang.Exception
java.lang.Exception
- if initialization failsprotected final net.sf.hibernate.Session getSession() throws DataAccessResourceFailureException, java.lang.IllegalStateException
DataAccessResourceFailureException
- if the Session couldn't be created
java.lang.IllegalStateException
- if no thread-bound Session found and allowCreate falseHibernateTemplate
protected final net.sf.hibernate.Session getSession(boolean allowCreate) throws DataAccessResourceFailureException, java.lang.IllegalStateException
allowCreate
- if a new Session should be created if no thread-bound found
DataAccessResourceFailureException
- if the Session couldn't be created
java.lang.IllegalStateException
- if no thread-bound Session found and allowCreate falseSessionFactoryUtils.getSession(SessionFactory, boolean)
protected final DataAccessException convertHibernateAccessException(net.sf.hibernate.HibernateException ex)
Delegates to the convertHibernateAccessException method of this DAO's HibernateTemplate.
ex
- HibernateException that occured
setHibernateTemplate(org.springframework.orm.hibernate.HibernateTemplate)
,
HibernateAccessor.convertHibernateAccessException(net.sf.hibernate.HibernateException)
protected final void closeSessionIfNecessary(net.sf.hibernate.Session session) throws CleanupFailureDataAccessException
session
- Session to close
DataAccessResourceFailureException
- if the Session couldn't be closed
CleanupFailureDataAccessException
SessionFactoryUtils.closeSessionIfNecessary(net.sf.hibernate.Session, net.sf.hibernate.SessionFactory)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |