-
JUST ONE SESSION FACTORY (per tenant ;) )
-
Scoping! There's lots of information on the web, but the right answer is to use your container.
-
Session per request
-
using flush (don't call flush explicitly!)
-
not committing transactions
- Map your aggregate roots correctly
- Make sure you get the right Id pattern
- Increment is SINGLE INSTANCE ONLY.
- Beware enums and dirty flags
- Yes, you really have to mark everything as virtual, including unrelated methods
- NHibernate is one, so don't wrap it.
- Query over
- ICriteria
- Linq
- Encapsulate queries, not "ISession", CQRS-ish.
- Beware lazy loading - user "Fetch"
- But don't disable lazy loading
- Fetch modes
- Projections
- HQL
- Multi-queries / Futures / Batching
- Composite type mappings make your ugly tables a little nicer
- Mapping expressions
- Use the framework to bridge the gulf of model / storage details (encryption, weird data mapping problems)