Stateless sessions

NHibernate sessions are stateful by default. In other words, they maintain the state of the entities that pass through them. During the course of execution of any functionality, following is what usually happens if you are using a NHibernate session:

  1. You open a new session.
  2. You begin a transaction on this session.
  3. You load some entities from the database using the session.
  4. The entities loaded are tracked in the identity map (session level cache), in case they are queried again.
  5. The entities are also kept in the second level cache if it is configured.
  6. You then update few properties on the entities.
  7. You then commit your NHibernate transaction to signal to NHibernate to persist your in-memory changes to the database (remember transitive ...

Get Learning NHibernate 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.