You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Rick Curtis <cu...@gmail.com> on 2011/07/13 00:10:38 UTC

FetchPlan question

Should I be able to remove an eager field from the default fetch plan? For
example, I have the following Entity snippet:

@Entity
public class ManyEagerNode {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected int id;

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
    Set<ManyEagerNode> setConnections = new HashSet<ManyEagerNode>();
...
}

and I would like to be able to mark the setConnections field as LAZY. I
thought I should be able to do something along these lines...

FetchPlan fp = em.getFetchPlan()
fp.removeField("org.apache.openjpa.persistence.graph.ManyEagerNode.setConnections");

I browsed the code and it's quite obvious that this will not work. Is this
by design, or an oversight? The docs seem to imply that the fetch plan can
used to mark fields as Eager, but not vice versa. I assume I could create a
new, non-default fetch plan and I could manually add my fields.... but I
would like to work directly with the default fetch plan.

Thoughts?

-- 
*Rick Curtis*

Re: FetchPlan question

Posted by Pinaki Poddar <pp...@apache.org>.
> Thoughts? 
I think you are correct. 
Our removeField() has weak semantics than excludeFields() - a method we do
not have!
But please run some test and let me know. 

If you tweaking things, see FetchPlan.requiresFetch() 

-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/FetchPlan-question-tp6577007p6577367.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: FetchPlan question

Posted by Pinaki Poddar <pp...@apache.org>.
> Creating a custom fetch group from scratch is painful for large objects, 
> especially when you want to only remove a few fields from the default
> fetch group. 

Agreed. The problem with fetch plan (despite it being an excellent feature
otherwise), it does not have a exclusion set. removeField() does not do that
exactly. The logic of 'fetch' checks a field for inclusion. I believe we
should upgrade to have an explicit excludeField(..) sort of semantics. Of
course, explicit exclusion should trump inclusion. 
 
That will address the issue of excluding few fields from default fetch group
rather than creating a new one from scratch for large objects. 

-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/FetchPlan-question-tp6577007p6583837.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: FetchPlan question

Posted by Rick Curtis <cu...@gmail.com>.
I got caught up trying to work on the 2.1.1 release. I hope to find some
time today or tomorrow to spend a few cycles on this issue. Be sure to keep
an eye out for updates.

On Wed, Jul 13, 2011 at 9:50 PM, berhack <be...@hotmail.com> wrote:

> Hi Rick,
>
> I was attempting to do the same thing when I stumbled upon this thread.
>  Did
> you make any head way?  It looks like the second if check seems to be the
> culprit (in FetchConfigurationImpl):
>
> private boolean includes(FieldMetaData fmd) {
>        if (hasFetchGroupAll()
>            || (fmd.isInDefaultFetchGroup()
>            && hasFetchGroupDefault())
>            || hasField(fmd.getFullName(false)))
>            return true;
>        String[] fgs = fmd.getCustomFetchGroups();
>        for (int i = 0; i < fgs.length; i++)
>            if (hasFetchGroup(fgs[i]))
>                return true;
>        return false;
>    }
>
> Creating a custom fetch group from scratch is painful for large objects,
> especially when you want to only remove a few fields from the default fetch
> group.
>
> --
>
-- 
*Rick Curtis*

Re: FetchPlan question

Posted by berhack <be...@hotmail.com>.
Hi Rick,

I was attempting to do the same thing when I stumbled upon this thread.  Did
you make any head way?  It looks like the second if check seems to be the
culprit (in FetchConfigurationImpl):

private boolean includes(FieldMetaData fmd) {
        if (hasFetchGroupAll()
            || (fmd.isInDefaultFetchGroup() 
            && hasFetchGroupDefault())
            || hasField(fmd.getFullName(false)))
            return true;
        String[] fgs = fmd.getCustomFetchGroups();
        for (int i = 0; i < fgs.length; i++)
            if (hasFetchGroup(fgs[i]))
                return true;
        return false; 
    }

Creating a custom fetch group from scratch is painful for large objects,
especially when you want to only remove a few fields from the default fetch
group.

--
View this message in context: http://openjpa.208410.n2.nabble.com/FetchPlan-question-tp6577007p6581703.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.