NHibernate Pitfalls: Stateless Sessions
This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.
Stateless sessions are a good thing: they offer a simplified API for performing updates, deletes and inserts, which does not require that the entities are known by the session beforehand and they can also offer some performance benefits. However, this comes at a cost.
It happens that stateless sessions do not support some of NHibernate’s features that we’ve become accustomed to:
- Interceptors: no way to use them;
- Events: never fired;
- Cascades: never happen;
- Dirty checking: not performed;
- Second-level cache: not used;
- Lazy loading: not supported.
So, if you need any of these, don’t use stateless sessions.