|
From: Peter K. (JIRA) <nh...@gm...> - 2011-06-30 21:23:48
|
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
|
|
From: Julian M. (JIRA) <nh...@gm...> - 2011-07-01 16:45:56
|
[ http://216.121.112.228/browse/NH-2784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21339#action_21339 ]
Julian Maughan commented on NH-2784:
------------------------------------
You need to provide more details before we can help. Your mappings would be a start. Also, what is generating the second SELECT statement? Even better is a test case that reproduces the issue: http://nhforge.org/blogs/nhibernate/archive/2008/10/04/the-best-way-to-solve-nhibernate-bugs-submit-good-unit-test.aspx
> 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
|
|
From: Peter K. (JIRA) <nh...@gm...> - 2011-07-04 14:53:06
|
[ http://216.121.112.228/browse/NH-2784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21347#action_21347 ]
Peter Kiers commented on NH-2784:
---------------------------------
I have a sample posted on StackOverflow: http://stackoverflow.com/questions/6518244/nhibernate-does-extra-select-on-missing-relations-even-using-eager-fetching
Would that be good enough?
> 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
|
|
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
|
|
From: Peter K. (JIRA) <nh...@gm...> - 2011-07-05 06:48:09
|
[ http://216.121.112.228/browse/NH-2784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21350#action_21350 ]
Peter Kiers commented on NH-2784:
---------------------------------
Yes, both statements are generated by that single Criteria query. And if I'd had more missing relations then I would get another select for each missing one. I will try ByCode mappings.
> 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
|