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.  [ 3 posts ] 
Author Message
 Post subject: Eager fetching more than 1 collection
PostPosted: Mon Feb 02, 2009 5:09 pm 
Newbie

Joined: Mon Feb 02, 2009 3:24 pm
Posts: 2
Hi

I am a NHibernate / Castle ActiveRecord user and ran into the following problem.

I have a root entity A which has a bag of Bees and Cees.

When eager fetching both the collections:

DetachedCriteria query = DetachedCriteria.For<A>(alias ?? "a");

query.SetFetchMode("Bees", FetchMode.Join);
query.SetFetchMode("Cees", FetchMode.Join);

the collection items are duplicated.

Say A has 2 bees and 3 cees, with eager fetch a.Bees & a.Cees both have a count of 6.

Believe this is due to the left joins that hibernate generates.

Setting the SetResultTransform(Transformers.DistinctRootEntity) makes no difference.

QUESTIONS:

1. Is there any other transformer which would eliminate the duplicates in the child collections?

2. Is using a set instead of a bag the preferred way to eliminate duplicates (if so can I map an ICollection<T> to a set)

Also are there any performance implications for using a set as opposed to a bag.

3. Also is there any good info on why hibernate does not try to eliminate duplicates by default?

Thanks

Ajai


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 12:54 pm 
Newbie

Joined: Tue Feb 03, 2009 12:01 pm
Posts: 1
I am not aware of other duplicate-eliminating transforms.

DistinctRootEntity will eliminate duplicates in the first table of a two-way join, but does not scale to n-way joins.

Rather than expecting NHib to puzzle through the cartesian product of an n-way join, simplify your code to return just two tables at a time.

First get A-Bees, then A-Cees, or let one of the collections be lazy-fetched.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 4:48 pm 
Newbie

Joined: Mon Feb 02, 2009 3:24 pm
Posts: 2
I can do that, but the same problem exists if say:

A has list of Bees (FetchMode.Join)
B has list of Cees (FetchMode.Join)

As a dev, not knowing anything better, I might specify there eager fetches as part of mapping file itself.

Which brings me back to my original question:

Is using a set as opposed to a bag the preferred method for domain mapping?

If so does NHibernate support mapping a ICollection<T> to Isei set?


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

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.