-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: cannot perform lazy loading in n-tier web application
PostPosted: Wed Nov 30, 2011 6:15 pm 
Newbie

Joined: Sat Nov 26, 2011 5:32 am
Posts: 2
I'm using NH to map DB to an object named `location` which has some properties and on List `<Attachments>` attachments (one-to-many relation with instance of `lcocation`).


I use lambda expression to init `location` istance:

public IList<T> GetAllByExpression(Expression<Func<T,bool>> expression)
{
using (ISession session = NHibernateHelper.OpenSession())
{
return session.Query<T>().Where(expression).ToList();
}
}

at some later point in the code I try to access `location.attachments` collection but get an exception:

> {"Initializing[Location#543c7367-08fa-4469-a252-8e2c6163be22]-failed
> to lazily initialize a collection of role: Location.Attachments, no
> session or session was closed"}

I understand the session is closed, but there is no much I can do.

I understand the session is closed, but there is no much I can do.

I have a dilema:
1) The code uses the collection after fetching from the DB and needs the session to still be open.
leaving the session open for the whole time is a bad practice. (without `using`).

2) Even if i leave the session open during the whole application runtime, I have build an n-tier web application.
The DAL should be general and not expose some implementation's session (NH in this case).

3) Eager loading seems to be the solution, but it's wastefull - as I'll have to eager load all the data in case of an object with list of other objects in it. (And that can even continue recurrsively)

What should I do?

TIA


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.