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:
|| From Type
|| Recursion Depth
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.