I also already posted this question on StackOverflow (http://
stackoverflow.com/questions/6518244/nhibernate-does-extra-select-on-
missing-relations-even-using-eager-fetching) but no reactions so far.
I stumbled on some unexpected behavior. We have some references in our
database with does not exist anymore. Somehow NHibernate preforms an
extra select query on non-existing relations even using Eager loading
on the criteria.

var orders = session.CreateCriteria<Order>().SetFetchMode("User",
FetchMode.Eager).List<Order>();

When ever there is an UserID in the Order table that does not exists
anymore then NHibernate preforms an aditional select query for that
item. So if I have 10+ missing relations there will be 10+ extra
select queries.

NHibernate console output:
NHibernate: SELECT this_.Id as Id0_1_, this_.OrderName as
OrderName0_1_, this_.U ser_id as User3_0_1_, user2_.Id as Id1_0_,
user2_.UserName as UserName1_0_ FROM [Order] this_ left outer join
[User] user2_ on this_.User_id=user2_.Id
NHibernate: SELECT user0_.Id as Id1_0_, user0_.UserName as
UserName1_0_ FROM [Us er] user0_ WHERE user0_.Id=@p0;@p0 = 3 [Type:
Int32 (0)]

As you can see NHibernate does a second query on the User references
that it cant find, even though I did do a join on the User table so it
should know already that the record isn't there. As we work with a
legacy database its no option to fix all missing relations inside our
database at this point. Is there an option to prevent this behavoir of
NHibernate as this could have serious impact on querying.

Thanks in advanced.

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