Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to manage session in NHibernate?

I'm new to NHibernate (my 1st big project with it).
I had been using a simple method of data access by creating the ISession object within a using block to do my grab my Object or list of Objects, and in that way the session was destroyed after exiting the code block.

This doesn't work in a situation where lazy-loading is required, however.
For example, if I have a Customer object that has a property which is a collection of Orders, then when the lazy-load is attempted, I get a Hibernate exception.
Anyone using a different method?

like image 333
Mark Struzinski Avatar asked Aug 28 '08 15:08

Mark Struzinski


2 Answers

Session management:

http://code.google.com/p/dot-net-reference-app/source/browse/trunk/src/Infrastructure/Impl/HybridSessionBuilder.cs

Session per request:

http://code.google.com/p/dot-net-reference-app/source/browse/trunk/src/Infrastructure/Impl/NHibernateSessionModule.cs

like image 56
Matt Hinze Avatar answered Oct 07 '22 17:10

Matt Hinze


check out the SummerOfNHibernate webcasts for a great tutorial... What you're looking for specifically doesn't come until webisode 5 or 6.

like image 24
Chris Conway Avatar answered Oct 07 '22 17:10

Chris Conway