Helper class that simplifies NHibernate data access code
For a list of all members of this type, see HibernateTemplate Members .
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
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 implementing 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 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.
Assembly: Spring.Data.NHibernate21 (in Spring.Data.NHibernate21.dll)