one-to-many and many-to-many relationship modeling

52 views
Skip to first unread message

Seymores

unread,
Jan 6, 2010, 10:52:11 AM1/6/10
to Gaelyk
Hi guys,

Not sure if this has been asked before but I'm interested to find out
how are you modeling one-to-many and many-to-many entity
relationship.

I find it hard to wrap my head around datastore that's no
relationtional.

Wilson MacGyver

unread,
Jan 6, 2010, 10:58:02 AM1/6/10
to gae...@googlegroups.com
the short answer is, for the most part. you don't.

a key value store system like most of the NOSQL systems
is designed for you to get and update values based on a key.
What you gain is the flexibility of schema free.

so, when you design your data, you have to design it with
that in mind.

Most of these systems are designed to purposely avoid joins
and operations of that nature due to problems that occur
when you have billions of datasets.

2010/1/6 Seymores <seym...@gmail.com>:

> --
> Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
> Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
> Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
> Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/gaelyk?hl=fr
>
>
>
>

--
Omnem crede diem tibi diluxisse supremum.

Guillaume Laforge

unread,
Jan 6, 2010, 11:00:22 AM1/6/10
to gae...@googlegroups.com
Yeah that's a good question, but that's not been asked yet.

I think, if I'm not mistaken, that one way of implementing one-to-many
would simply to have a property in your first entity that lists Keys,
and have the linked entities also have a property listing Keys back in
the other direction. I suspect this is how they mimick one-to-many
with the JDO / JPA implementations.


2010/1/6 Seymores <seym...@gmail.com>:

> --
> Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
> Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
> Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
> Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/gaelyk?hl=fr
>
>
>
>

--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Wilson MacGyver

unread,
Jan 6, 2010, 11:02:32 AM1/6/10
to gae...@googlegroups.com
That's possible. I do notice that JPA degrades quickly when
you use it that way when I was testing it in the initial release.

2010/1/6 Guillaume Laforge <glaf...@gmail.com>:

--

Guillaume Laforge

unread,
Jan 6, 2010, 11:09:55 AM1/6/10
to gae...@googlegroups.com
I'm not really surprised, as as you explained in your previous email,
a datastore is basically a special beast and applying a paradigm on
top of it doesn't necessarily make that paradigm efficient :-) (to
liberally paraphrase what you said!)

That said, there are some really poweful things you can do with such a
datastore that would be very hard with a classical RDBMS anyway.
For instance, with the datastore, you can query every entity (here I
really mean across all entity kinds) and find all queries that have a
certain tag.
With a relation database, you'd have to run as many queries, and
aggregate the results somehow programmatically.
With the datastore, just one query is needed for that.
Pretty powerful.

So in general, as you said, it's good to be able to place oneself in a
different mindset, so as to take the most of the different paradigm,
but it's not always easy, with all the habits and knowledge we have
with one paradigm!

Guillaume

2010/1/6 Wilson MacGyver <wmac...@gmail.com>:

Seymores

unread,
Jan 6, 2010, 8:10:55 PM1/6/10
to Gaelyk
I'm curious how it works, do you have some sample code?

Right now, the only example I can find is the code from groovy console
-- really helpful.


sey

On Jan 7, 12:02 am, Wilson MacGyver <wmacgy...@gmail.com> wrote:
> That's possible. I do notice that JPA degrades quickly when
> you use it that way when I was testing it in the initial release.
>

> 2010/1/6 Guillaume Laforge <glafo...@gmail.com>:


>
>
>
> > Yeah that's a good question, but that's not been asked yet.
>
> > I think, if I'm not mistaken, that one way of implementing one-to-many
> > would simply to have a property in your first entity that lists Keys,
> > and have the linked entities also have a property listing Keys back in
> > the other direction. I suspect this is how they mimick one-to-many
> > with the JDO / JPA implementations.
>

> > 2010/1/6 Seymores <seymo...@gmail.com>:

Guillaume Laforge

unread,
Jan 7, 2010, 2:28:17 AM1/7/10
to gae...@googlegroups.com
Hi,

2010/1/7 Seymores <seym...@gmail.com>:


> I'm curious how it works, do you have some sample code?

I don't have code handy actually.
But in pseudo code, it could look something like this:

Imagine a many-to-many relationship where a student can have many
teachers and a teacher many students.

def s1 = new Entity("student #1")
def s2 = ...

def t1 = new Entity("teacher #1")
def t2 = ...

s1.teachers = [t1.key, t3.key]
t2.students = [s1.key, s2.key, s3.key]

That should look something like the above I believe.

> Right now, the only example I can find is the code from groovy console
> -- really helpful.

Thanks... but probably not that helpful, in the sense that there's no
relationships, since there's just one entity :-)
But at some point, that would be good to have various samples of
various scenarios, so that it gives good hints on how to best
implement things!

Guillaume

Seymores

unread,
Jan 7, 2010, 9:15:05 PM1/7/10
to Gaelyk
Modeling the relationship is one thing and another is how to query
them back, this which I learn from GroovyConsole's handling of the
query for script by tags. :-)


On Jan 7, 3:28 pm, Guillaume Laforge <glafo...@gmail.com> wrote:
> Hi,
>
> 2010/1/7 Seymores <seymo...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages