You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Henno Vermeulen <he...@huizemolenaar.nl> on 2011/04/05 17:42:09 UTC

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

RE: questions about FetchAttribute recursionDepth

Posted by Henno Vermeulen <he...@huizemolenaar.nl>.
The detach-related settings in persistence.xml we use are:

	<property name="openjpa.DetachState" value="fetch-groups(DetachedStateField=false)" />
	<property name="openjpa.AutoDetach" value="commit" />

In almost all our use cases the fetched entities are serialized and sent to a remote client. The client is currently not required to have OpenJPA on its classpath (although it does use enhanced entities).

Henno

-----Oorspronkelijk bericht-----
Van: Michael Dick [mailto:michael.d.dick@gmail.com] 
Verzonden: dinsdag 5 april 2011 21:45
Aan: users@openjpa.apache.org
Onderwerp: Re: questions about FetchAttribute recursionDepth

Hi Henno,

Have you set the openjpa.DetachState property or are you using the default
value?

-mike

On Tue, Apr 5, 2011 at 11:17 AM, Henno Vermeulen <he...@huizemolenaar.nl>wrote:

> 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:henno@huizemolenaar.nl]
> Verzonden: dinsdag 5 april 2011 17:42
> Aan: 'users@openjpa.apache.org'
> 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
>

Re: questions about FetchAttribute recursionDepth

Posted by Michael Dick <mi...@gmail.com>.
Hi Henno,

Have you set the openjpa.DetachState property or are you using the default
value?

-mike

On Tue, Apr 5, 2011 at 11:17 AM, Henno Vermeulen <he...@huizemolenaar.nl>wrote:

> 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:henno@huizemolenaar.nl]
> Verzonden: dinsdag 5 april 2011 17:42
> Aan: 'users@openjpa.apache.org'
> 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
>

RE: questions about FetchAttribute recursionDepth

Posted by Henno Vermeulen <he...@huizemolenaar.nl>.
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:henno@huizemolenaar.nl] 
Verzonden: dinsdag 5 april 2011 17:42
Aan: 'users@openjpa.apache.org'
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