session.CreateCriteria(typeof(ForthTable)).List();
sesson.CreateCriteria(typeof(Level)).List();

Two queries, and you loaded everything.

On Tue, Jan 20, 2009 at 2:27 PM, Thomas Koch <[email protected]> wrote:

>
> Hi Will and Ayende - thanks for the replies.  :-)
>
> I know there are Select N+1 going on here. The main cause of all
> theses selects is that I have three different classes that constitutes
> a tree with three levels: Level1 -> Level2 -> Level3.
>
> I have 20 rows at Level1, 40 rows at Level2 and 300 rows at Level3.
> Each level has a list of the next level - mapped as a bag in the .hbm
> files. Level2 and Level3 each have a list of objects pointing back to
> themselves. Moreover the lowest level (Level3) has two many-to-many
> collections to a fourth class (table). In fact it is this lowest level
> that is causing most of the selects.
>
> As far as I understand I can only put fetch="join" on one property on
> a mapped class and with all these references on Level2 and Level3 it
> seems to me that its usability is limited in my scenario.
>
> The workaround I have been thinking of is to create a class for all
> ten tables, many-to-many tables included, and then simply do ten
> LoadAll(). I would then build object graph manually instead of having
> NHibernate do it.
>
> Is that what you guys would do in a similar situation?
>
> Regards
> Thomas
>
>
>
>
> On 20 Jan., 20:07, Ayende Rahien <[email protected]> wrote:
> > You have a select N+1, and it is a problem.It is pretty common to do
> > preloading on app startup, but that should be even close to that number.
> > You need to optimize your startup queries.
> >
> > On Tue, Jan 20, 2009 at 2:01 PM, Thomas Koch <[email protected]> wrote:
> >
> > > Hi - I have a discussion with some co-workers regarding the number of
> > > hits that NHibernate is performing against our database.
> >
> > > Our setup: We are developing ASP.NET applications using NHibernate 2.0
> > > for the data access.
> >
> > > We have a web-application containing static information stored in 7
> > > inter-connected classes based on 10 underlying tables. This static
> > > information is needed all the time, thus we load all of this into
> > > memory when the application starts.
> >
> > > Using NHibernate to create and fill this object hierarchy we get 1100
> > > selects being sent to the database. This takes around 6 seconds to
> > > complete.
> >
> > > My co-workers feel that this is an accident waiting to happed, whereas
> > > I myself consider this less of problem - after all we only do this
> > > once on application start-up.
> >
> > > What do you think? Is 1100 select statements on application start
> > > something to be afraid of?
> >
> > > Any opinion/advice is appreciated.
> >
> > > Regards
> > > Thomas
> >
>

--~--~---------~--~----~------------~-------~--~----~
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