Book Image

Learning NHibernate 4

Book Image

Learning NHibernate 4

Overview of this book

Table of Contents (18 chapters)
Learning NHibernate 4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 persistence?).

  8. NHibernate uses dirty checking to find out which of the entities in the session have changed and only persists the changes to the database.

  9. As part of above, NHibernate also cascades the database operations down to the collections/associations...