Uploaded image for project: 'NHibernate'
  1. NHibernate
  2. NH-2534

Join-fetching a many-to-one with property-ref results in select n+1 problem

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0.0.GA
    • Fix Version/s: None
    • Component/s: Core

      Description

      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.

        Activity

        Hide
        liko81 Keith Shannon added a comment -

        I was also able to reproduce this issue in NH 2.1.2, so it's a long-standing issue with join fetching.

        Show
        liko81 Keith Shannon added a comment - I was also able to reproduce this issue in NH 2.1.2, so it's a long-standing issue with join fetching.
        Hide
        johanhaest Johan Haest added a comment -

        Any workarounds yet? Or even fixes?

        Show
        johanhaest Johan Haest added a comment - Any workarounds yet? Or even fixes?
        Hide
        kamil.kliczbor Kamil Kliczbor added a comment -

        Johan Haest: 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.

        Show
        kamil.kliczbor Kamil Kliczbor added a comment - Johan Haest : 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.
        Hide
        johanhaest Johan Haest added a comment -

        Not when your join is not on the primary key of the many to one class right?

        Show
        johanhaest Johan Haest added a comment - Not when your join is not on the primary key of the many to one class right?
        Hide
        kamil.kliczbor Kamil Kliczbor added a comment -

        Right. We had join to other column that Id, but under certain circumstances we could abandon this approach.

        Show
        kamil.kliczbor Kamil Kliczbor added a comment - Right. We had join to other column that Id, but under certain circumstances we could abandon this approach.

          People

          • Assignee:
            Unassigned
            Reporter:
            cremor cremor
          • Votes:
            13 Vote for this issue
            Watchers:
            12 Start watching this issue

            Dates

            • Created:
              Updated:

              Who's Looking?