getSession() or getHibernateTemplate.getSession()?

I'm unsure of which of the above to use in our DAOs (which extend HibernateDAOSupport).

The SpringFramework API doc on HibernateTemplate.getSession() is thus:
protected Session getSession()
Return a Session for use by this template.
Returns a new Session in case of alwaysUseNewSession" (using the same JDBC Connection as a transactional Session, if applicable), a pre-bound Session in case of "allowCreate" turned off, and a pre-bound or new Session else (new only if no transactional or otherwise pre-bound Session exists).

The SpringFramework API doc on getSession() is thus:
protected final Session getSession()
   throws DataAccessResourceFailureException,
   IllegalStateException
Get a Hibernate Session, either from the current transaction or a new one. The latter is only allowed if the "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 (via HibernateInterceptor), or use it in combination with releaseSession.

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.

你可能感兴趣的:(thread,Hibernate,bean,jdbc)