Hi Ravi,

the relation is still a one to one relation because the
categoryGroupRelation holds a categoryId as a primary Key, so the
relation only holds one or zero categoryId for ever Category and
thereby every Category has only one CategoryGroup.

But my question is more about design principles. Isn't it better to
separate the data from relations? Lets say you create a User class on
the first Version of you App. You store thinks like eMail, names,
birthdays and so on in this class. In a second version of you App you
want to extend the database schema with user groups. By then you only
need to add two new classes Groups and UserGroupsRelations to
accomplish this and don't need to extends or alter the original User
class (Think about altering all the old User objects that are still in
the datastore, what are the inital values for this new attribute?).

There is another advantage: If you implement the userGroups relation
in the UserClass you only get all Users from one Group by making a
query over all Users insted of just checking the relations. You could
simply get allUsersFromAGroup and allGroupsFromAUser over this class.

Tell me how you would implement this and what are your experiences?

Thanks and greetings
Poe

On 7 Jul., 16:46, Ravi Sharma <[email protected]> wrote:
> Hi Poe,
> You have just implemented relational many to many relation.
>
> But this design is perfectly fine but just think if you need one to many 
> relation only then in your case you will be writing 2 entities while u could 
> just write one by saving catehoryGroup id in category it self.
> And when u want to read category and catehorygroup, u need to read three 
> entities while u could read just two.
>
> So for one to many relations I will use unowned relation and save some write 
> and read :).
>
> GAE doesn't say u can't think relational :).
>
> Thanks
> Ravi
>
> Sent from my iPhone
>
> On 7 Jul 2010, at 15:18, poe <[email protected]> wrote:
>
>
>
> > I've got a question regarding this.
>
> > Isn't it kind of "nicer" regarding the design to not store relational
> > Attributes in a core table/class. In the given example I would
> > implement this like this:
>
> > @PersistenceCapable
> > public class Categories
> > {
> >   �...@primarykey
> >   �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >        private Long Id;
>
> >    No owned or unowner object here
> >    ...
> > }
>
> > @PersistenceCapable
> > public class CategoryGroups
> > {
> >       �...@primarykey
> >   �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >        private Long Id;
> >    ...
> > }
>
> > @PersistenceCapable
> > public class CategoryGroupRelation {
>
> >   @PrimaryKey
> >   @Persistent(mappedBy="category")
> >   private Long categoryId;
>
> >   @Persistent(mappedBy="categorygroups"
> >   private Long categoryGroupId;
>
> > }
>
> > Isn't it better to design the tables this way? I don't like relational
> > attributes in a core database class. What do you think?
>
> > Greets
> > Poe
>
> > On 7 Jul., 01:25, AC <[email protected]> wrote:
> >> Thanks.  That answers my question.
>
> >> On Jul 6, 3:18 pm, Ravi Sharma <[email protected]> wrote:
>
> >>> You need to understand the concept of Entity group here, and need to
> >>> understand the owned relation and unowned relation.
> >>> Think of owned and unowned relation like this
> >>> You(your house) and your TV has owned relationship, your house has TV, no 
> >>> ne
> >>> can see it from outside, and if your friend want the same tv he need to 
> >>> buy
> >>> the same TV and own it. And at one point if you ask who all watching my TV
> >>> then it will be just you not your friend as he has his own TV(although 
> >>> same
> >>> kind of TV).
>
> >>> But You and your favourite movie theatre has unowned relationship, you 
> >>> dont
> >>> own it, anyone who knows the address of theatre can go and watch movie. 
> >>> and
> >>> at one moment 1000s of people might be watching the same movie/theatre
>
> >>> Back to your question.....
>
> >>> Categories(3)/CategoryGroups(4)     is an example for owned relation.
> >>> CategoryGroup(4) will be available to Category(3) only and if you create
> >>> another category Cateory(10) with same category group it will just create
> >>> another version of categoryGroup CategoryGroup(11) in that category. But 
> >>> you
> >>> may see that CategoryGroup 11 and CategoryGroup 4 both are Entertainment.
>
> >>> In your case many categories can have same categoryGroup.So instead of 
> >>> using
> >>> owned relationship, you should use unowned relationship.
>
> >>> Instead of this
> >>> @Persistent
> >>>    private CategoryGroups Group;
>
> >>> define this
> >>> @Persistent
> >>>    private Key categoryGroupId;
>
> >>> and save key of CategoryGroup rather then full object. (Dont buy a TV for
> >>> every other rmovie you want to watch, just buy a movie theatre ticket go
> >>> there and use that :) )
>
> >>> I hope u get the idea,  you can learn more from here....
>
> >>>http://code.google.com/appengine/docs/java/datastore/relationships.html
>
> >>> spare me if you dont like my example... :)
>
> >>> Ravi.
>
> >>> On Tue, Jul 6, 2010 at 5:47 PM, AC <[email protected]> wrote:
> >>>> I just started fooling around w/ GAE this weekend.
>
> >>>> I have a Categories class and a CategoryGroup class.  The idea is that
> >>>> every category must be grouped.  For example the CategoryGroup
> >>>> "Entertainment" can be assigned to many Categories, such as "movies",
> >>>> "music" and "television".
>
> >>>> Here are my classes.
>
> >>>> @PersistenceCapable
> >>>> public class Categories
> >>>> {
> >>>>   �...@primarykey
> >>>>   �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >>>>        private Key Id;
>
> >>>>   �...@persistent
> >>>>    private CategoryGroups Group;
>
> >>>>       �...@persistent
> >>>>        private boolean IsDeleted;
>
> >>>>       �...@persistent
> >>>>        private String Name;
>
> >>>>       �...@persistent
> >>>>        private Date CreateDate;
>
> >>>>       �...@persistent
> >>>>       �...@column(allowsNull="true")
> >>>>    private Date ModifiedDate;
> >>>> }
>
> >>>> @PersistenceCapable
> >>>> public class CategoryGroups
> >>>> {
> >>>>       �...@primarykey
> >>>>   �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >>>>        private Key Id;
>
> >>>>       �...@persistent
> >>>>    boolean IsDeleted;
>
> >>>>       �...@persistent
> >>>>    String Name;
>
> >>>>       �...@persistent
> >>>>    Date CreateDate;
>
> >>>>       �...@persistent
> >>>>       �...@column(allowsNull="true")
> >>>>    Date ModifiedDate;
> >>>> }
>
> >>>> First I add a record to CategoryGroups.  When I query all, the reult
> >>>> is :
>
> >>>> CategoryGroups(2)
>
> >>>> Next, I add a record to Categories.  When I query all CategoryGroups,
> >>>> the result is :
>
> >>>> Categories(3)/CategoryGroups(4)
> >>>> CategoryGroups(2)
>
> >>>> I do not doubt that this works as it was designed to, however, coming
> >>>> from a RDBMS background, this is very confusing to me.  The screen I
> >>>> created to manage Categories now has "Entertainment" listed twice in
> >>>> the CategoryGroups select box.  Is there a better approach to achieve
> >>>> my goal?
>
> >>>> Any advice is much appreciated.
>
> >>>> --
> >>>> 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]<google-appengine-java%2B
> >>>>  [email protected]>
> >>>> .
> >>>> For more options, visit this group at
> >>>>http://groups.google.com/group/google-appengine-java?hl=en.
>
> > --
> > 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 
> > athttp://groups.google.com/group/google-appengine-java?hl=en.

-- 
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