I suspect this is an issue with detaching! I turned on the trace and printed a message after entityManager.find. When I have a structure of 10 levels deep and fetch the deepest child, OpenJPA cleanly fetches the leaf ProductCategory with 1 query, then prints my message, but then starts recursively fetching all parents.
When I set the recursionDepth to 2 the SQL shows that it fetches one more parent, then print my debug message, then fetch the rest. Is this a known problem or should I report this? Regards, Henno Vermeulen Huize Molenaar. -----Oorspronkelijk bericht----- Van: Henno Vermeulen [mailto:[email protected]] Verzonden: dinsdag 5 april 2011 17:42 Aan: '[email protected]' Onderwerp: questions about FetchAttribute recursionDepth I have a ProductCategory entity with a reference to a parent ProductCategory. I wish to eagerly fetch one parent but not the parent's parent. We always use fetchplans (using entityManager.getFetchPlan().addFetchGroups(...)) and we always detach according to the fetchplan, so I tried: @FetchGroup(name = "ProductCategoryParentNoRecursion", attributes = { @FetchAttribute(name = "parent", recursionDepth = 1) }) Question 1: according to the latest manual a recursionDepth of 1 is the default, but I have also seen it mentioned in Jira or the newsgroup that it was changed so that the recursion depth has no limit by default. Which one is it? Question 2: no matter what recursionDepth I use (I tried -1, 0, 1 and 2), it always fetches the parent's parent. I tested this with a ProductCategory structure of A -> B -> C. When I use entityManager.find to find C by it's id, I expect C.parent.parent to be null but it is not. Why is this? (I did not access the parent before detaching). Regards, Henno Vermeulen Huize Molenaar
