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 <acol...@gmail.com> wrote:
> Thanks.  That answers my question.
>
> On Jul 6, 3:18 pm, Ravi Sharma <ping2r...@gmail.com> 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 <acol...@gmail.com> 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
> > > google-appengine-j...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2B
> > >  unsubscr...@googlegroups.com>
> > > .
> > > 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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to