From: Julian M. (JIRA) <nh...@gm...> - 2011-07-04 16:53:06
|
[ http://216.121.112.228/browse/NH-2784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21348#action_21348 ] Julian Maughan commented on NH-2784: ------------------------------------ I had a look at your FNH mappings. I don't really known FNH, but it looks correct. Having said that I was unable to reproduce the problem using a ByCode mapping: mapper.Class<Order>(m => { m.Table("`Order`"); m.Id(x => x.Id, map => map.Generator(Generators.Assigned)); m.Property(model => model.Name); m.ManyToOne<User>(model => model.User, map => map.Column("TheUser")); }); mapper.Class<User>(m => { m.Table("`User`"); m.Id(x => x.Id, map => map.Generator(Generators.Assigned)); m.Property(model => model.Name); }); Are you saying that both SELECT statements are executed by the Criteria query, or is the second one only executed later on when you access the Order with ID = 3? > NHibernate does extra select on each missing relations, even using an eager fetching. > ------------------------------------------------------------------------------------- > > Key: NH-2784 > URL: http://216.121.112.228/browse/NH-2784 > Project: NHibernate > Issue Type: Bug > Components: Core > Affects Versions: 3.1.0 > Reporter: Peter Kiers > > When I do an eager join on a relation table, whenever the relation is missing it will generate an additional query for each missing relation. > Table layout / data: > TableName: Order > +----+-----------+--------+ > | Id | OrderName | UserId | > +----+-----------+--------+ > | 1 | OrderA | 1 | > | 2 | OrderB | 2 | > | 3 | OrderC | 3 | > +-------------------------+ > TableName: User > +----+-----------+ > | Id | UserName | > +----+-----------+ > | 1 | User1 | > | 2 | User2 | > +----------------+ > var orders = session.CreateCriteria<Order>().SetFetchMode("User", > FetchMode.Eager).List<Order>(); > Console output: > NHibernate: SELECT this_.Id as Id0_1_, this_.OrderName as OrderName0_1_, this_.User_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 [User] user0_ WHERE user0_.Id=@p0;@p0 = 3 [Type: Int32 (0)] > As you can see it tries to get UserID 3 (which doesn't exists) but it should already know it isn't there as I did a eager fetchmode on that table. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://216.121.112.228/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |