Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

HibernateTemplate Class

Generic version of the Helper class that simplifies NHibernate data access code

For a list of all members of this type, see HibernateTemplate Members .

System.Object
   HibernateAccessor
      HibernateTemplate

[Visual Basic]
Public Class HibernateTemplate
    Inherits HibernateAccessor
    Implements IHibernateOperations, ICommonHibernateOperations
[C#]
public class HibernateTemplate : HibernateAccessor, IHibernateOperations, ICommonHibernateOperations

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

Typically used to implement data access or business logic services that use NHibernate within their implementation but are Hibernate-agnostic in their interface. The latter or code calling the latter only have to deal with domain objects.

The central method is Execute() supporting Hibernate access code which implements the HibernateCallback interface. It provides NHibernate Session handling such that neither the IHibernateCallback implementation nor the calling code needs to explicitly care about retrieving/closing NHibernate Sessions, or handling Session lifecycle exceptions. For typical single step actions, there are various convenience methods (Find, Load, SaveOrUpdate, Delete).

Can be used within a service implementation via direct instantiation with a ISessionFactory reference, or get prepared in an application context and given to services as an object reference. Note: The ISessionFactory should always be configured as an object in the application context, in the first case given to the service directly, in the second case to the prepared template.

This class can be considered as a direct alternative to working with the raw Hibernate Session API (through SessionFactoryUtils.Session).

LocalSessionFactoryObject is the preferred way of obtaining a reference to a specific NHibernate ISessionFactory.

Requirements

Namespace: Spring.Data.NHibernate.Generic

Assembly: Spring.Data.NHibernate20 (in Spring.Data.NHibernate20.dll)

See Also

HibernateTemplate Members | Spring.Data.NHibernate.Generic Namespace