OpenJPA
  1. OpenJPA
  2. OPENJPA-944

FetchAttribute.recursionDepth = -1 does not load properly self referenced entities in a complex relation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0, 1.2.0
    • Fix Version/s: 2.0.0-beta
    • Component/s: jdbc, kernel
    • Labels:
      None
    • Environment:
      JDK: Sun 1.5
      Database: Derby 10.2.2.0
      OS: Windows XP
    • Patch Info:
      Patch Available

      Description

      A problem with loading recursively referenced entities was found when there is a complex relation of the following kind:
      Leaf <> BranchConnection <> Branch(1) <- Branch(2) <- ...
      where Branch has a self reference to itself.

      Using a FetchPlan with a fetch group that has a fetch attribute with recursionDepth=-1 does not produce the expected result and only the first of the Branch nodes is loaded.
      Loading a Leaf with 5 branches in a row and traversing through them fails right on level 3 (starting from 5 downwards) which leads to the thought that OpenJPA loads only the first element (along with its direct parent).

        Issue Links

          Activity

          Donald Woods made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Donald Woods made changes -
          Fix Version/s 2.0.0-beta [ 12314149 ]
          Fix Version/s 2.0.0 [ 12314019 ]
          Pinaki Poddar made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.0.0 [ 12314019 ]
          Resolution Fixed [ 1 ]
          Pinaki Poddar made changes -
          Assignee Pinaki Poddar [ ppoddar@apache.org ]
          Donald Woods made changes -
          Patch Info [Patch Available]
          Hide
          Yanko Zhivkov added a comment -

          Attached patch files for fixing that issue for OpenJPA versions 1.0.1 and 1.2.1. The same changes could be used for the other versions as well.

          I think the problem is that the recursion depth is not calculated properly. When the FetchConfiguration is created for every field-to-field relation only the type of the FieldMetaData is taken into consideration. This causes a confusion of what the real recursion depth is.
          For example if the field BranchConnection.branch refers to Branch and Branch.parent has a reference to Branch then there is the following field metadata:

          Field From Type Recursion Depth
          branch Branch 1
          parent Branch -1

          When the mappings are built and OpenJPA gets to BranchConnection.branch - > Branch.parent and tries to add the new field Branch.parent it will try to find an already existing limit and will compare the From Type of the new field to the From Type of the existing mappings (parents of the new mapping).
          As the second mapping in the table has not been created yet it will grab the first one which is not what we expect and will set recursion depth 1. This prevents from getting the real recursion depth and only the first parent of the Branch connected to BranchConnection will be loaded.

          For fixing this behavior a new check for the field name was added. This makes sure that when the recursion depth is being determined only the mappings that are of the same kind (fromField and fromType) will be taken into consideration.

          Show
          Yanko Zhivkov added a comment - Attached patch files for fixing that issue for OpenJPA versions 1.0.1 and 1.2.1. The same changes could be used for the other versions as well. I think the problem is that the recursion depth is not calculated properly. When the FetchConfiguration is created for every field-to-field relation only the type of the FieldMetaData is taken into consideration. This causes a confusion of what the real recursion depth is. For example if the field BranchConnection.branch refers to Branch and Branch.parent has a reference to Branch then there is the following field metadata: Field From Type Recursion Depth branch Branch 1 parent Branch -1 When the mappings are built and OpenJPA gets to BranchConnection.branch - > Branch.parent and tries to add the new field Branch.parent it will try to find an already existing limit and will compare the From Type of the new field to the From Type of the existing mappings (parents of the new mapping). As the second mapping in the table has not been created yet it will grab the first one which is not what we expect and will set recursion depth 1. This prevents from getting the real recursion depth and only the first parent of the Branch connected to BranchConnection will be loaded. For fixing this behavior a new check for the field name was added. This makes sure that when the recursion depth is being determined only the mappings that are of the same kind (fromField and fromType) will be taken into consideration.
          Hide
          Yanko Zhivkov added a comment -

          Could be related to OPENJPA-911. The only difference is that the attached to this bug test case works for release 1.0.0 whilst my test case does not work for any released version of OpenJPA.

          Show
          Yanko Zhivkov added a comment - Could be related to OPENJPA-911 . The only difference is that the attached to this bug test case works for release 1.0.0 whilst my test case does not work for any released version of OpenJPA.
          Yanko Zhivkov made changes -
          Link This issue is related to OPENJPA-911 [ OPENJPA-911 ]
          Yanko Zhivkov made changes -
          Field Original Value New Value
          Attachment openjpa_complex_relation_recursion_test.zip [ 12401060 ]
          Hide
          Yanko Zhivkov added a comment - - edited

          Attached a test case that shows the error. I tried the test case with 1.0.0, 1.0.1, 1.0.3, 1.1.0 and 1.2.0 and even with the latest trunk code but neither of them work.

          For running the test case unzip the zip file and execute from a shell:
          mvn install

          The provided test case extends SingleEMFTestCase and can directly be copied into openjpa-persistence-jdbc/src/test for being executed within there as well.

          Show
          Yanko Zhivkov added a comment - - edited Attached a test case that shows the error. I tried the test case with 1.0.0, 1.0.1, 1.0.3, 1.1.0 and 1.2.0 and even with the latest trunk code but neither of them work. For running the test case unzip the zip file and execute from a shell: mvn install The provided test case extends SingleEMFTestCase and can directly be copied into openjpa-persistence-jdbc/src/test for being executed within there as well.
          Yanko Zhivkov created issue -

            People

            • Assignee:
              Pinaki Poddar
              Reporter:
              Yanko Zhivkov
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development