Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

HibernateDaoSupport.DoGetSession Method

Get a Hibernate Session, either from the current transaction or a new one. The latter is only allowed if "allowCreate" is true.

[Visual Basic]
Protected Sub DoGetSession( _
   ByVal allowCreate As Boolean _
protected ISession DoGetSession(
   bool allowCreate


if a non-transactional Session should be created when no transactional Session can be found for the current thread

Return Value

Hibernate session.


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.


Exception TypeCondition
DataAccessResourceFailureException If the Session couldn't be created
InvalidOperationException if no thread-bound Session found and allowCreate false

See Also

HibernateDaoSupport Class | Spring.Data.NHibernate.Generic.Support Namespace | ReleaseSession