openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <ppod...@apache.org>
Subject Re: Multiple join fetches
Date Tue, 07 Apr 2009 23:02:53 GMT

Hi Daryl,
> Ah, so modifying the fetch plan is for the lifetime of the em? I think I like that.

Yes. But there is more to it.

say em has a fetchplan (say f1).
any query q created from that em has the clone of fetchplan f1 (say f2) to begin with. If
f2 is changed, that impacts q but not its parent em. 

Also you can use a stack pattern with these fetch plans. as follows:

  FetchPlan f1 = em.getFetchPlan();
  FetchPlan f2 = em.pushFetchPlan(); // f2 is clone of f1
  f2.setSomething(something);
  em.doSomething(); // f2 is active now
  em.popFetchPlan(); 
  em.doSomething(); // f1 is active now

 



On Tue, Apr 7, 2009 at 1:11 AM, Jay McHugh <jaydmchugh@gmail.com> wrote:

>
> If that doesn't work - or you (cannot/do not want to) eagerly fetch
> the relationship all of the time - a quick stab at what using fetch
> groups might look like this:
>
> <example>
>
> // assuming you already have an entity manager named 'entityManager'
> OpenJPAEntityManager em = OpenJPAPersistence.cast(entityManager);
>
> FetchPlan plan = em.getFetchPlan();
> plan.addField(GrandParent.class, "parents");
> plan.addField(Parent.class, "children");
>
> Query query = em.createQuery("select gp from GrandParent as gp");
>
> </example>
>

Ah, so modifying the fetch plan is for the lifetime of the em? I think I
like that. Thanks for the help.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com




-----
Pinaki Poddar                      http://ppoddar.blogspot.com/
                                      
http://www.linkedin.com/in/pinakipoddar
OpenJPA PMC Member/Committer
JPA Expert Group Member
-- 
View this message in context: http://n2.nabble.com/Multiple-join-fetches-tp2593566p2602050.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message