openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yanko Zhivkov (JIRA)" <>
Subject [jira] Updated: (OPENJPA-944) FetchAttribute.recursionDepth = -1 does not load properly self referenced entities in a complex relation
Date Tue, 21 Apr 2009 00:07:47 GMT


Yanko Zhivkov updated OPENJPA-944:

    Attachment: fix_recursive_entity_loading-OPENJPA-944-openjpa1.2.1.patch

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.

> FetchAttribute.recursionDepth = -1 does not load properly self referenced entities in
a complex relation
> --------------------------------------------------------------------------------------------------------
>                 Key: OPENJPA-944
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc, kernel
>    Affects Versions: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0, 1.2.0
>         Environment: JDK: Sun 1.5
> Database: Derby
> OS: Windows XP 
>            Reporter: Yanko Zhivkov
>            Priority: Critical
>         Attachments: fix_recursive_entity_loading-OPENJPA-944-openjpa1.0.1.patch, fix_recursive_entity_loading-OPENJPA-944-openjpa1.2.1.patch,
> 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).

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message