Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Java Persistence with Tertiary Relationship (http://www.velocityreviews.com/forums/t390368-java-persistence-with-tertiary-relationship.html)

Harry 01-26-2007 04:59 AM

Java Persistence with Tertiary Relationship
 
Hi All,

As we know, we can perform relationship between two entities, using
@OneToOne, @OneToMany, @ManyToOne, @ManyToMany

Can I use JPA to persist a Tertiary Relationship?

For example, the relationship between User, Role and Module, which can
represent whether a User instance having a particular Role can access a
Module instance.

Thanks,
Harry


Danno 01-28-2007 04:10 AM

Re: Java Persistence with Tertiary Relationship
 


On Jan 25, 9:59 pm, "Harry" <harrywo...@gmail.com> wrote:
> Hi All,
>
> As we know, we can perform relationship between two entities, using
> @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
>
> Can I use JPA to persist a Tertiary Relationship?
>
> For example, the relationship between User, Role and Module, which can
> represent whether a User instance having a particular Role can access a
> Module instance.
>
> Thanks,
> Harry


That doesn't make sense


Harry 01-29-2007 01:32 AM

Re: Java Persistence with Tertiary Relationship
 
Can you elaborate more?
Which part doesn't make sense
and how to solve if I am in this case.

On Jan 28, 12:10 pm, "Danno" <dh.evolutionn...@gmail.com> wrote:
> On Jan 25, 9:59 pm, "Harry" <harrywo...@gmail.com> wrote:
>
> > Hi All,

>
> > As we know, we can perform relationship between two entities, using
> > @OneToOne, @OneToMany, @ManyToOne, @ManyToMany

>
> > Can I use JPA to persist a Tertiary Relationship?

>
> > For example, the relationship between User, Role and Module, which can
> > represent whether a User instance having a particular Role can access a
> > Module instance.

>
> > Thanks,
> > HarryThat doesn't make sense



Daniel Pitts 01-29-2007 01:41 AM

Re: Java Persistence with Tertiary Relationship
 


On Jan 25, 8:59 pm, "Harry" <harrywo...@gmail.com> wrote:
> Hi All,
>
> As we know, we can perform relationship between two entities, using
> @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
>
> Can I use JPA to persist a Tertiary Relationship?
>
> For example, the relationship between User, Role and Module, which can
> represent whether a User instance having a particular Role can access a
> Module instance.
>
> Thanks,
> Harry


So, a User has a specific Roles, and the Roles allow access to
specific Modules?
Would that look like:

class User {
Collection<Role> roles;
// Extra user data.
}

class Role {
Collection<Module> accessableModules;
Collection<User> users;
// Extra role data
}

class Module {
// module data
}

So, this would be
User many-to-many Role
Role one-to-many Module

Hope this helps,
Daniel.


Harry 01-29-2007 02:07 AM

Re: Java Persistence with Tertiary Relationship
 
Thanks for that in advance
Perhaps it's my problem on not giving a good example.

What I mean is really when tertiary relationship exists ( I think you
should know tertiary does exist in ERD)
I try to use another example.
Person-Order-LineItem relationship

-----------------
| Line Item |
-----------------
|
-------------- | -----------
| Person | ------- ( ) ------ | Order |
-------------- -----------

In this case, Line Item instances appear when a relationship between
the Person and Order forms.
Hope my example does a good illustration.

Thanks for your help.
Harry


On Jan 29, 9:41 am, "Daniel Pitts" <googlegrou...@coloraura.com>
wrote:
> On Jan 25, 8:59 pm, "Harry" <harrywo...@gmail.com> wrote:
>
> > Hi All,

>
> > As we know, we can perform relationship between two entities, using
> > @OneToOne, @OneToMany, @ManyToOne, @ManyToMany

>
> > Can I use JPA to persist a Tertiary Relationship?

>
> > For example, the relationship between User, Role and Module, which can
> > represent whether a User instance having a particular Role can access a
> > Module instance.

>
> > Thanks,
> > HarrySo, a User has a specific Roles, and the Roles allow access to

> specific Modules?
> Would that look like:
>
> class User {
> Collection<Role> roles;
> // Extra user data.
>
> }class Role {
> Collection<Module> accessableModules;
> Collection<User> users;
> // Extra role data
>
> }class Module {
> // module data
>
> }So, this would be
> User many-to-many Role
> Role one-to-many Module
>
> Hope this helps,
> Daniel.



Danno 01-29-2007 04:13 AM

Re: Java Persistence with Tertiary Relationship
 


On Jan 28, 7:07 pm, "Harry" <harrywo...@gmail.com> wrote:
> Thanks for that in advance
> Perhaps it's my problem on not giving a good example.
>
> What I mean is really when tertiary relationship exists ( I think you
> should know tertiary does exist in ERD)
> I try to use another example.
> Person-Order-LineItem relationship
>
> -----------------
> | Line Item |
> -----------------
> |
> -------------- | -----------
> | Person | ------- ( ) ------ | Order |
> -------------- -----------
>


A Person Order Line Item Relationship would look like this...

Person (1)------------(∞) Order (1)--------------(∞) LineItem

There would be no need for a "tertiary" relationship.



Danno 01-29-2007 04:15 AM

Re: Java Persistence with Tertiary Relationship
 


On Jan 28, 6:41 pm, "Daniel Pitts" <googlegrou...@coloraura.com>
wrote:
> On Jan 25, 8:59 pm, "Harry" <harrywo...@gmail.com> wrote:
>
> > Hi All,

>
> > As we know, we can perform relationship between two entities, using
> > @OneToOne, @OneToMany, @ManyToOne, @ManyToMany

>
> > Can I use JPA to persist a Tertiary Relationship?

>
> > For example, the relationship between User, Role and Module, which can
> > represent whether a User instance having a particular Role can access a
> > Module instance.

>
> > Thanks,
> > HarrySo, a User has a specific Roles, and the Roles allow access to

> specific Modules?
> Would that look like:
>
> class User {
> Collection<Role> roles;
> // Extra user data.
>
> }class Role {
> Collection<Module> accessableModules;
> Collection<User> users;
> // Extra role data
>
> }class Module {
> // module data
>
> }So, this would be
> User many-to-many Role
> Role one-to-many Module
>
> Hope this helps,
> Daniel.


I agree, I would have Module have access to roles, and roles not have
access to modules. But that's the same design I was thinking.



Harry 01-29-2007 06:59 AM

Re: Java Persistence with Tertiary Relationship
 
So, what you mean is to convert every tertiary relationship to two
relationships each in between two of the three entities?
Is it really possible to convert all kinds of relationships like this?

Thanks
Harry

On Jan 29, 12:15 pm, "Danno" <dh.evolutionn...@gmail.com> wrote:
> On Jan 28, 6:41 pm, "Daniel Pitts" <googlegrou...@coloraura.com>
> wrote:
>
>
>
> > On Jan 25, 8:59 pm, "Harry" <harrywo...@gmail.com> wrote:

>
> > > Hi All,

>
> > > As we know, we can perform relationship between two entities, using
> > > @OneToOne, @OneToMany, @ManyToOne, @ManyToMany

>
> > > Can I use JPA to persist a Tertiary Relationship?

>
> > > For example, the relationship between User, Role and Module, which can
> > > represent whether a User instance having a particular Role can access a
> > > Module instance.

>
> > > Thanks,
> > > HarrySo, a User has a specific Roles, and the Roles allow access to

> > specific Modules?
> > Would that look like:

>
> > class User {
> > Collection<Role> roles;
> > // Extra user data.

>
> > }class Role {
> > Collection<Module> accessableModules;
> > Collection<User> users;
> > // Extra role data

>
> > }class Module {
> > // module data

>
> > }So, this would be
> > User many-to-many Role
> > Role one-to-many Module

>
> > Hope this helps,
> > Daniel.I agree, I would have Module have access to roles, and roles not have

> access to modules. But that's the same design I was thinking.



Danno 01-29-2007 03:32 PM

Re: Java Persistence with Tertiary Relationship
 
Well, I wouldn't treat anything anyone says as religious doctrine.
So, to say, "convert ALL kinds of relationships like this" won't help
you out either. You have to model your ERD and object mappings based
on reality. You will find that this idea of tertiary relationship
where you have a prop table with 3 keys and nothing else will less
likely exist.

On Jan 28, 11:59 pm, "Harry" <harrywo...@gmail.com> wrote:
> So, what you mean is to convert every tertiary relationship to two
> relationships each in between two of the three entities?
> Is it really possible to convert all kinds of relationships like this?
>
> Thanks
> Harry
>
> On Jan 29, 12:15 pm, "Danno" <dh.evolutionn...@gmail.com> wrote:
>
> > On Jan 28, 6:41 pm, "Daniel Pitts" <googlegrou...@coloraura.com>
> > wrote:

>
> > > On Jan 25, 8:59 pm, "Harry" <harrywo...@gmail.com> wrote:

>
> > > > Hi All,

>
> > > > As we know, we can perform relationship between two entities, using
> > > > @OneToOne, @OneToMany, @ManyToOne, @ManyToMany

>
> > > > Can I use JPA to persist a Tertiary Relationship?

>
> > > > For example, the relationship between User, Role and Module, which can
> > > > represent whether a User instance having a particular Role can access a
> > > > Module instance.

>
> > > > Thanks,
> > > > HarrySo, a User has a specific Roles, and the Roles allow access to
> > > specific Modules?
> > > Would that look like:

>
> > > class User {
> > > Collection<Role> roles;
> > > // Extra user data.

>
> > > }class Role {
> > > Collection<Module> accessableModules;
> > > Collection<User> users;
> > > // Extra role data

>
> > > }class Module {
> > > // module data

>
> > > }So, this would be
> > > User many-to-many Role
> > > Role one-to-many Module

>
> > > Hope this helps,
> > > Daniel.I agree, I would have Module have access to roles, and roles not have

> > access to modules. But that's the same design I was thinking.




All times are GMT. The time now is 12:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.