There was a typo I just noticed.

The first line of my email was supposed to read:

> I have been banging my head against FetchPlans, and all of my attempts
> have returned either an exception -OR- the default plan.

Hopefully that didn't cause any confusion.

Jay

Jay D. McHugh wrote:
> Hello again,
> 
> I have been banging my head against FetchPlans, and all of my attempts
> have returned either an exception of the default plan.
> 
> In an attempt to really restrict what is comming back I came up with the
> following:
> 
> <codesnip>
> OpenJPAEntityManager em = OpenJPAPersistence.cast(entityManager);
> FetchPlan plan = em.getFetchPlan();
> 
> plan.clearFetchGroups();
> plan.addField(Project.class, "projectID");
> plan.setMaxFetchDepth(0);
> 
> System.out.println("FetchPlan contains the following fields...");
> 
> for (String field : plan.getFields()) {
>       System.out.println(field);      
> }
>                       
> System.out.println("FetchPlan contains the following groups...");
>                       
> for (String group : plan.getFetchGroups()) {
>       System.out.println(group);
> }
> 
> spec = em.find(Project.class, projectID);
> 
> em.detach(spec);
> </codesnip>
> 
> When I run this block of code I get the following debug output:
> 
> FetchPlan contains the following fields...
> net.jnwd.ejb.entity.Project.projectID
> FetchPlan contains the following groups...
> 
> And then the JAXB conversion returns the full entity with all of it's
> children.
> 
> Have I misunderstood what FetchPlans are for and/or how they are used?
> 
> (Note: I have also tried annotating my entity with FetchGroups and they
> did the same thing).
> 
> Thanks in advance,
> 
> Jay
> 
> Pinaki Poddar wrote:
>> Hi,
>>   You can look in OpenJPA documentation [1][2] and if you have access to the 
>> source code (we are open source:) then take a look at Test cases [3]
>>  
>> [1] 
>> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_runtime_jpafetch
>> [2] 
>> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_fetch
>> [3] openjpa-kernel/.../org.apache.openjpa.persistence.kernel.TestFetchPlan
>>
>>
>> Thanks for suggesting FetchPlan.
>>
>> Is there a reference that you could suggest on finding out more about
>> FetchPlan - preferably with examples?
>>
>> Thanks in advance,
>>
>> Jay
>>
>> Pinaki Poddar wrote:
>>> Hi,
>>>> I have a whole hierarchy of entities that I am transforming using JAXB
>>>> to send XML to a browser client.  But, the amount of detail that I am
>>>> sending as XML changes depending on the type of request. 
>>>  OpenJPA's dynamic FetchPlan is the correct solution for such use case. 
>>> With FetchPlan you can control the exact details that you need in the 
>>> entity classes that are to be sent to the browser client.
>>>
>>>> I have been making several entity classes to
>>>> describe the same database table.  
>>> Not needed if you consider using FetchPlan.
>>>   
>>>
>>>
>>> Hello all,
>>>
>>> I have what may be a strange requirement (I guess you will have to
>>> decide on that).  But, there is a fairly long amount of background
>>> before you get to my actual question.
>>>
>>> Background -
>>> I have a whole hierarchy of entities that I am transforming using JAXB
>>> to send XML to a browser client.  But, the amount of detail that I am
>>> sending as XML changes depending on the type of request.
>>>
>>> For example (simplified):
>>> A project has many details
>>> Each detail contains a component
>>> Each component contains several attributes
>>>
>>> Sometimes I want to be able to send back only the XML for the project
>>> (without any of its children) and sometimes, I want to send back the
>>> whole structure.  The reason for this is that a fully populated entity
>>> can become extremely large (sometimes several Mb) - and sending that
>>> much much information as the response to an AJAX call ends up killing
>>> performance.
>>>
>>> To accomplish this, I have been making several entity classes to
>>> describe the same database table.  'Project' is the full hierarchy and
>>> 'FlatProject' is the project and its details - without the components.
>>>
>>> But, to support the various scenarios for exactly how much detail I want
>>> to transmit has let to a lot of duplication on entities (each a
>>> partially defined versions of the real data structure).
>>>
>>> Question -
>>> Inheritance does not really satisfy my need.  In my database, everything
>>> matches the 'fully defined' version of my entities.
>>>
>>> So, is there a way to 'mask' my entities so that I only have one entity
>>> class that actually refers to the database table but several masks that
>>> limit how much of the data is visible?
>>>
>>> Hopefully I am not the first person to have a need like this.
>>>
>>> Thanks in advance,
>>>
>>>
>>> Jay
>>>
>>>
>>>
>>>
>>> -----
>>> Pinaki Poddar                      http://ppoddar.blogspot.com/
>>>                                       
>>> http://www.linkedin.com/in/pinakipoddar
>>> OpenJPA PMC Member/Committer
>>> JPA Expert Group Member
>>
>>
>>
>> -----
>> Pinaki Poddar                      http://ppoddar.blogspot.com/
>>                                       
>> http://www.linkedin.com/in/pinakipoddar
>> OpenJPA PMC Member/Committer
>> JPA Expert Group Member

Reply via email to