You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "Jay D. McHugh" <ja...@gmail.com> on 2009/03/27 17:28:56 UTC

'Masking' fields in an Entity

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

Re: 'Masking' fields in an Entity

Posted by "Jay D. McHugh" <ja...@gmail.com>.
Dynamic FetchPlans are now among my new favorite things (except now, I
need to rewrite a lot of code to remove my fake entity hacks).

I will definitely try to put together a sample (and blog posting, and
wiki entry on Geronimo site).

Jay

Pinaki Poddar wrote:
> Hi,
>   I like what you are doing and believe that it is a predominant use case for multi-tier for OpenJPA/JPA based web applications. 
> 
>   Please consider writing up a small, self-contained sample (preferably without the application server scaffolding) to demonstrate your solution to integrate JAXB marshaling with constrained serialization support available via dynamic fetch plans of OpenJPA.
> 
>   Such samples can be made available with OpenJPA samples distribution. This will allow other community members to benefit from your contributions. Kevin had offered a project in Google Summer of Code [1] for similar purpose of enriching the corpus of samples that ship with OpenJPA. You can touch base with him to explore further (also there is $$$ for a GSoC project:).
> 
> [1] http://wiki.apache.org/general/SummerOfCode2009#openjpa-project
> 
> 
> Thanks for the hint.
> 
> The setting you suggested caused deployment errors for me (I am
> deploying my app to Geronimo 2.1.3 which uses OpenJPA 1.0.3).
> 
> But, it looks like this setting will work for me:
> 
> <property name="openjpa.DetachState"
> value="fetch-groups(AccessUnloaded=true)" />
> 
> The only strange thing is that my unloaded booleans show up in XML as
> being false (rather than not showing up at all).  So I'll just have to
> make sure I include them in my fetch group.
> 
> Thanks for all your help,
> 
> Jay
> 
> Pinaki Poddar wrote:
>>> If I set the DetachState to something else, would I be able to get it
>>> to simply return blanks/nulls for the unloaded fields?
>> Try :
>> <property name="openjpa.DetachState" value="fetch-groups(DetachStateField=false)"/>
>>
>>
>>
>> -----
>> 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

Re: 'Masking' fields in an Entity

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
  I like what you are doing and believe that it is a predominant use case for multi-tier for OpenJPA/JPA based web applications. 

  Please consider writing up a small, self-contained sample (preferably without the application server scaffolding) to demonstrate your solution to integrate JAXB marshaling with constrained serialization support available via dynamic fetch plans of OpenJPA.

  Such samples can be made available with OpenJPA samples distribution. This will allow other community members to benefit from your contributions. Kevin had offered a project in Google Summer of Code [1] for similar purpose of enriching the corpus of samples that ship with OpenJPA. You can touch base with him to explore further (also there is $$$ for a GSoC project:).

[1] http://wiki.apache.org/general/SummerOfCode2009#openjpa-project


Thanks for the hint.

The setting you suggested caused deployment errors for me (I am
deploying my app to Geronimo 2.1.3 which uses OpenJPA 1.0.3).

But, it looks like this setting will work for me:

<property name="openjpa.DetachState"
value="fetch-groups(AccessUnloaded=true)" />

The only strange thing is that my unloaded booleans show up in XML as
being false (rather than not showing up at all).  So I'll just have to
make sure I include them in my fetch group.

Thanks for all your help,

Jay

Pinaki Poddar wrote:
>> If I set the DetachState to something else, would I be able to get it
>> to simply return blanks/nulls for the unloaded fields?
> 
> Try :
> <property name="openjpa.DetachState" value="fetch-groups(DetachStateField=false)"/>
> 
> 
> 
> -----
> 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
-- 
View this message in context: http://n2.nabble.com/%27Masking%27-fields-in-an-Entity-tp2545263p2563797.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: 'Masking' fields in an Entity

Posted by "Jay D. McHugh" <ja...@gmail.com>.
Thanks for the hint.

The setting you suggested caused deployment errors for me (I am
deploying my app to Geronimo 2.1.3 which uses OpenJPA 1.0.3).

But, it looks like this setting will work for me:

<property name="openjpa.DetachState"
value="fetch-groups(AccessUnloaded=true)" />

The only strange thing is that my unloaded booleans show up in XML as
being false (rather than not showing up at all).  So I'll just have to
make sure I include them in my fetch group.

Thanks for all your help,

Jay

Pinaki Poddar wrote:
>> If I set the DetachState to something else, would I be able to get it
>> to simply return blanks/nulls for the unloaded fields?
> 
> Try :
> <property name="openjpa.DetachState" value="fetch-groups(DetachStateField=false)"/>
> 
> 
> 
> -----
> Pinaki Poddar                      http://ppoddar.blogspot.com/
>                                       
> http://www.linkedin.com/in/pinakipoddar
> OpenJPA PMC Member/Committer
> JPA Expert Group Member

Re: 'Masking' fields in an Entity

Posted by Pinaki Poddar <pp...@apache.org>.
> If I set the DetachState to something else, would I be able to get it
> to simply return blanks/nulls for the unloaded fields?

Try :
<property name="openjpa.DetachState" value="fetch-groups(DetachStateField=false)"/>



-----
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/%27Masking%27-fields-in-an-Entity-tp2545263p2563035.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: 'Masking' fields in an Entity

Posted by Jay McHugh <ja...@gmail.com>.
Thank you for the additional insight.

Switching the DetachState is making things more clear.  I had it set
to a value of "all" before based on some example (not sure where from
though).

Here are answers to your questions - Hopefully by the time I finish
answering them all, I will have it working.

1) It is detached.
2) SInce changing the value of DetachState, I now get an exception.
3) The instance is being converted with JAXB marshaller immediately
after being loaded from the database.  So - no serialize/deserialize.

Here is the full routine that is loading the entity from the database
and marshalling it (slightly simplified):

public String sendXML(String projectID, User user) {
	StringWriter xml = new StringWriter();

	OpenJPAEntityManager em = getPM(entityManager);
	FetchPlan plan = em.getFetchPlan();

	plan.setMaxFetchDepth(0);
	plan.clearFetchGroups();
	plan.clearFields();

	plan.addField(Project.class, "projectID");
	plan.addField(Project.class, "projectNumber");
	plan.addField(Project.class, "projectVersion");
	plan.addField(Project.class, "projectRevision");
	plan.addField(Project.class, "projectItem");

	Project spec = em.find(Project.class, projectID);
	spec = em.detach(spec);

	try {
		JAXBContext context = JAXBContext.newInstance(spec.getClass());
		Marshaller m = context.createMarshaller();
		m.marshal(spec, xml);
	} catch (JAXBException je) {
		System.out.println("JAXB Exception: " + je.getMessage());
		je.printStackTrace();
	} catch (Exception e) {
		System.out.println("Some other exception doing JAXB conversion: " +
e.getMessage());
		e.printStackTrace();
	}

	System.out.println("XML: " + xml);
		
	return xml.toString();
}

Well, I've gone through your questions - And, I am much closer (maybe)
to where I need to be.  But, the 'm.marshall' call is trying to call
all of the getters of my entity.  So, it is kicking out
IllegalStateExceptions since the fields are unloaded.

If I set the DetachState to something else, would I be able to get it
to simply return blanks/nulls for the unloaded fields?

Thanks again for you help so far,

Jay
On Tue, Mar 31, 2009 at 12:20 AM, Pinaki Poddar <pp...@apache.org> wrote:
>
> Hi,
>  You are correct in detaching the instance with the current fetch plan. In theory, now the detached instance should only have the fields selected by the fetch plan. If that is not happening then verify the following in order
>  1. Is the instance detached? OpenJPAEntityManager.isDetached(pc)
>  2. What happens if you access and fields that is not supposed to be loaded in the detached instance?
> Configure openjpa.DetachState [1] with  AccessUnloaded to throw an exception on any attempt to acess any unloaded field.
>  3. If the detached instane is serialized and deserialized, which fields in the deserialized object are populated?
>
>  The above steps to ascertain that when JAXB is xmlizing the instance, inadvertently no fields are getting loaded as a side-effect.
>
>  You have to tell me more about the process that convertes these instances into XML -- such as when is this process is triggered? Which fields of the managed instance are processed by this XMLization process? Is there any possibility that a field will get loaded as a side-effect? Please note that any pc.getXXX() on a managed instance pc will load the field XXX.
>
>
> [1] http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_behavior
>
> -----
> 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/%27Masking%27-fields-in-an-Entity-tp2545263p2561243.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Re: 'Masking' fields in an Entity

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
  You are correct in detaching the instance with the current fetch plan. In theory, now the detached instance should only have the fields selected by the fetch plan. If that is not happening then verify the following in order
  1. Is the instance detached? OpenJPAEntityManager.isDetached(pc)
  2. What happens if you access and fields that is not supposed to be loaded in the detached instance?
Configure openjpa.DetachState [1] with  AccessUnloaded to throw an exception on any attempt to acess any unloaded field.
  3. If the detached instane is serialized and deserialized, which fields in the deserialized object are populated?
  
  The above steps to ascertain that when JAXB is xmlizing the instance, inadvertently no fields are getting loaded as a side-effect.

  You have to tell me more about the process that convertes these instances into XML -- such as when is this process is triggered? Which fields of the managed instance are processed by this XMLization process? Is there any possibility that a field will get loaded as a side-effect? Please note that any pc.getXXX() on a managed instance pc will load the field XXX.

  
[1] http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_behavior

-----
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/%27Masking%27-fields-in-an-Entity-tp2545263p2561243.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: 'Masking' fields in an Entity

Posted by "Jay D. McHugh" <ja...@gmail.com>.
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

Re: 'Masking' fields in an Entity

Posted by "Jay D. McHugh" <ja...@gmail.com>.
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

Re: 'Masking' fields in an Entity

Posted by Pinaki Poddar <pp...@apache.org>.
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
-- 
View this message in context: http://n2.nabble.com/%27Masking%27-fields-in-an-Entity-tp2545263p2546695.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: 'Masking' fields in an Entity

Posted by "Jay D. McHugh" <ja...@gmail.com>.
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

Re: 'Masking' fields in an Entity

Posted by Pinaki Poddar <pp...@apache.org>.
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
-- 
View this message in context: http://n2.nabble.com/%27Masking%27-fields-in-an-Entity-tp2545263p2546173.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.