Daryl,

You can also set a fetch plan on a single query.  But, you have to cast
the query to OpenJPAQuery (similarly to the way you cast the entity
manager).

I had some problems getting to work that I didn't have time to figure
out - so I went with setting fetch plans on the entity manager.

Jay

Daryl Stultz wrote:
> On Tue, Apr 7, 2009 at 1:11 AM, Jay McHugh <[email protected]> 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.
> 

Reply via email to