Hi James. JDO allows this, yes, but App Engine's datastore does not support
joins. Hence, even though the standard technically supports this type of
query, you will not be able to execute it in App Engine.

For one-to-one relationships, you can use an embedded object to achieve this
kind of query:

http://code.google.com/appengine/docs/java/datastore/dataclasses.html#Embedded_Classes

For many-to-one, you will have to use the tips that leszek already listed --
either do multiple queries and reconcile them in memory or find an effective
way to deal with the redundancy. Now that the task queue API is available
for Java, it is much easier to perform schema migrations and large datastore
bulk updates (e.g. changing the value of a particular field across many
entities or adding a field to all entities) than it has been.

- Jason

On Mon, Sep 7, 2009 at 3:53 AM, James H <[email protected]> wrote:

>
> Right, denormalization is promoted by the Max Ross video as in your
> 2nd case so from a software design perspective can the "copy fields"
> in Employee be contained in their own class and referenced from
> Employee in a fashion that allows JDO to still work such as:
>
> class CompanyFK {
>   // copy of property fiels from Company
>  @Persistent private String companyName;
>  @Persistent private String businessArea;
>
>  @ManyToOne
>  private Company company;
> }
>
> class Employee {
>   @Persistent String name;
>  @Persistent String address;
>
>   CompanyFK compnayFK
> }
>
> This way all entities that include a FK to Company would use CompanyFK
> and denormalized relations such as this would be managable (ie rather
> than copy/paste of fields across many Entities).  Does JDO allow this
> level of control?
>
> On Sep 7, 4:44 am, leszek <[email protected]> wrote:
> > I'm not sure if your taking of the problem is correct. To my mind it
> > runs:
> >
> > You have Company and Employee. Company has many Employees and Employee
> > is working for one company. "Normalized" version looks like:
> >
> > class Company {
> >
> >    @Persistent private String companyName;
> >    @Persistent private String businessArea;
> > ...
> >
> > }
> >
> > class Employee {
> >
> >   @Persistent private String name;
> >   @Persistent private String address;
> >   ....
> >   @ManyToOne
> >   private Company company;
> >
> > }
> >
> > If you want to get all Employess working for a company you should
> > execute:
> >   "SELECT * FROM Employee e WHERE e.company.companyName = :nameParam"
> >
> > or if you want all Emloyees working for all IT companies you execute:
> >   "SELECT * FROM Employee e WHERE e.company.businessArea = 'IT' "
> > ...
> > But this query will not work in Google App Engine.
> >
> > The solution is to resolve this query programmaticaly by running
> > several queries and filter it in memory or to "denormalize" this
> > scheme by moving some fields from Company to Employee
> >
> > Something like:
> >
> > class Epmloyee {
> >   @Persistent String name;
> >   @Persistent String address;
> >
> >   // copy of property fiels from Company
> >   @Persistent private String companyName;
> >   @Persistent private String businessArea;
> >
> >   @ManyToOne
> >   private Company company;
> >
> > }
> >
> > and run
> >   "SELECT Object(Employee) FROM Employee e WHERE e.companyName
> > = :nameParam"
> >
> > The first solution allows keeping "normalized" version but the cost is
> > less effective query, the second requires to break strictly normalized
> > pattern but the query is much more effective (I think that it can be
> > 10 or more times more effective). Also the second solution requires
> > more time while writing and updating.
> > But it is up to you what is more important, it is classical dilemma:
> > more "reads" or more "writes".
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to