-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with eager loading
PostPosted: Mon Jul 14, 2008 10:03 am 
Newbie

Joined: Tue Jul 01, 2008 2:37 am
Posts: 15
Hi,

Should eager loading of a collection within an object cause the object to be loaded multiple times?

Example: Should this query return multiple cars if there is only 1 car in the database (that has 2 doors)?
Dim criteria As ICriteria = SessionHandler.CurrentSession.CreateCriteria(GetType(Car)).Add(Expression.Eq("CarId", 1).SetFetchMode("Doors", NHibernate.FetchMode.Eager).List(Of Car)()


In my query, it returns a list of 2 cars (the same cars)...am I misunderstanding the use of fetchmodes? Shouldn't the fetch modes just fetch the Door objects of the Car? Is there an other way to do this?

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 10:48 am 
Newbie

Joined: Tue Jul 01, 2008 2:37 am
Posts: 15
Hmm...I found this: .SetResultTransformer(CriteriaUtil.DistinctRootEntity)
and find it pretty awkward that it should be used...
What if I need fetchmodes in collections of collections, will NHibernate also load duplicate objects? Eg, will there be 4 door objects in the car if each door has 2 windows (and the windows of the doors are eagerly loaded)?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 11:13 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
It's by design, have a look here:

http://www.hibernate.org/117.html#A12

and

http://jira.nhibernate.org/browse/NH-748

It's a faq for hibernate, but it's the same in nhibernate. Btw. the duplicates are all references to the same object instance. Hibernate does not instantiate the object more than ones.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 3:02 pm 
Newbie

Joined: Tue Jul 01, 2008 2:37 am
Posts: 15
Thanks. Nice response.

"It should be also obvious why resultset row-based "limit" operations, such as setFirstResult(5) and setMaxResults(10) do not work with these kind of eager fetch queries. If you limit the resultset to a certain number of rows, you cut off data randomly. One day Hibernate might be smart enough to know that if you call setFirstResult() or setMaxResults() it should not use a join, but a second SQL SELECT. "

Do you know if nhibernate already supports the "firstresult" and "maxresults" with eager loading at this moment?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 5:12 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Sorry, I don't know ...

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.