You need to look into the unit of work pattern.   As you noted, your
NH session is closing before you attempt to access those lazy loaded
relation objects.  If the session were still open, they would load as
you expect.

So, the answer is not to open another session.  The answer is to leave
your original session open.

If you are writing a web app, the standard is to open a session at the
start of a request and leave it open till the request is processed.

On Tue, Oct 21, 2008 at 1:08 PM, Tigraine <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I am completely new to NH and just started building a project using NH
> while learning how to use it.
>
> I apologize if this question has been asked again or I missed
> something in the documentation, but I simply couldn't find an answer
> to this.
>
> So:
>
> The following Diagram shows my Domain Objects:
> http://tigraine.at/model.png
>
> AccountInformation and Address/ShippingAddress are Component mappings
> so that everything gets persisted into one table.
>
> The only headache I am getting is my many-to-one relationship from
> Address to Country.
> I want to use lazy loading (I could load it right there, but I'll see
> the same problem arise with Products and Orders etc etc), so I get a
> LazyInitializationException whenever I access the Country property on
> the Address object.
>
> Now, clearly this is intended, the session is gone so I need another
> to load this.
> (I found 
> http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/collections.html#collections-lazy
> on this)
>
> But how? I clearly don't want to have my Domain objects to know of my
> repository. I wanted to keep them unaware of their persistance so I
> can easily Mock the Repository on my Tests.
>
> In case you wonder how I got to this point:
> I have been following this guide on HibernatingRhinos until now ..:
> http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx.
>
> I appreciate any help / suggestions on this.
> Thanks,
> Tigraine
>
> Btw: Did I mention that I really like NH? I've been working with
> Linq2Sql and EntityFramework lately and NHibernate feels so much
> better and more testable. Thank you...
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to