Hi all.

I have a complex object graph. There is a root entity which has a set of
collections (some of them are pretty big), entities in collections have
their own collections etc.. - a kind of tree. I need to fetch this tree with
minimum performance hit for database. I have tried 2 options for now:
1st - load root entity, and then navigate through properties to load all
child and grandchild collections, ofcourse set fetch="subselect" in mapping
file before, to prevent select n+1 problem
2nd - use approach, described here
http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/06/eager-loading-aggregate-with-many-child-collections.aspx,
where different collections load by different queries, but session is smart
enough, to merge different result to object graph, initializing different
collections.

But i can't use 1st approach, because i can't define fetch plan on a global
level (number of reasons), and i can't use 2nd approach, because it seems
that it works fine for 1st level collection only, selecting deeper level
collections will produce cartesian product, which will grow with level of
query of collection.

What i thought about, is would it be possible to use approach based on
several queries, like 2nd approach i mentioned. The difference is i tried to
start fetching not from the root entity level, but from the level i have to
fetch next, after i already fetched with previous query. For example:

        [Test]
        public void Test1()
        {
            // load root entity
            Country c = _session
                .CreateQuery("from Country where Name = 'Germany'")
                .List<Country>()[0];

            // trying to load 1st level child collection
            _sess
                .CreateQuery("from Customer cs where cs.Country = :c")
                .SetParameter("c", c)
                .List();

            Assert.That(NHibernateUtil.IsInitialized(c.Customers)); // fails
        }

I thought that session will initialize Country.Customers collection, but it
is not.
Ofcourse i could use eager join for this collection and others at the same
level, but as i said this will causes cartesian product for deeper
collections.
I'm not sure that what i did is valid, maybe it is invalid by design,
however it seems that session can initialize customers collection, since it
"knows" to which country selected customers belongs.

Just wanted to ask, how people solve same problems.

-- 
Best regards,
Andrew Melnichuk

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