NHibernate Core Interfaces

Summary

There are several core interfaces that can be used in any NHibernate application to store and retrieve persistent objects and control transactions.

ISession Interface

The ISession interface is the primary interface used by NHibernate applications.

The ISession interface exposes methods for finding, saving, updating, and deleting objects, and is often referred to as the Persistence Manager.

The ISession object is lightweight and is inexpensive to create and destroy.

A NHibernate session can be thought of as a collection of loaded objects relating to a single unit of work.

ISessionFactory Interface

The ISessionFactory is costly to create and should be shared among application threads.

There is typically a single instance of ISessionFactory for the whole application, but if the application accesses multiple databases using NHibernate, a separate ISessionFactory object is required for each database.

The ISessionFactory caches generated SQL statements and other mapping metadata that NHibernate uses at runtime.

Configuration Interface

The Configuration object is used to configure NHibernate.

The application uses a Configuration instance to specify the location of mapping documents and to set NHibernate-specific properties before creating the ISessionFactory.

ITransaction Interface

The ITransaction interface is an optional API and used by NHibernate applications for managing database transactions.

IQuery Interface

The IQuery interface is used to execute queries against the database, while also controlling how the query is executed.

The IQuery interface must be used in the ISession that created it.

ICriteria Interface

The ICriteria interface is used to create and executed object-oriented queries.

IUserType, ICompositeUserType, IParameterizedType and IUserCollectionType Interfaces

These interfaces are provided to let you create your own custom types.