Description
cremor created an issue — 7th February 2011, 0:58:25:
The attached test shows that a
many-to-one
association referencing an unique property (instead of the Id) results in a select n+1 problem. Although the first statement contains the correct join, all associated entities are fetched one by one after the join select. (Entities with the same value in the unique column are even fetched more than once.)The interesting point is that this bug only occurs if the referenced entities are already in the session cache. If they are not, no additional select statements are created.
Keith Shannon added a comment — 11th March 2011, 13:35:09:
I was also able to reproduce this issue in NH 2.1.2, so it's a long-standing issue with join fetching.
Johan Haest added a comment — 27th November 2013, 9:38:20:
Any workarounds yet? Or even fixes?
Kamil Kliczbor added a comment — 29th November 2013, 8:48:41:
<~johanhaest>: we had the same issue in our project. The symptom was the same. Finally we gave up with the property-ref reference and switched to normal foreign key relationship (it was possible). And I think that solution is not so trivial.
Johan Haest added a comment — 29th November 2013, 9:14:51:
Not when your join is not on the primary key of the many to one class right?
Kamil Kliczbor added a comment — 29th November 2013, 10:46:28:
Right. We had join to other column that Id, but under certain circumstances we could abandon this approach.