Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

Java Persistence with Tertiary Relationship

Thread view: 
Harry - 26 Jan 2007 04:59 GMT
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 - 28 Jan 2007 04:10 GMT
> Hi All,
>
[quoted text clipped - 9 lines]
> Thanks,
> Harry

That doesn't make sense
Harry - 29 Jan 2007 01:32 GMT
Can you elaborate more?
Which part doesn't make sense
and how to solve if I am in this case.

> > Hi All,
>
[quoted text clipped - 9 lines]
> > Thanks,
> > HarryThat doesn't make sense
Daniel Pitts - 29 Jan 2007 01:41 GMT
> Hi All,
>
[quoted text clipped - 9 lines]
> 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 - 29 Jan 2007 02:07 GMT
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:

> > Hi All,
>
[quoted text clipped - 30 lines]
> Hope this helps,
> Daniel.
Danno - 29 Jan 2007 04:13 GMT
> Thanks for that in advance
> Perhaps it's my problem on not giving a good example.
[quoted text clipped - 11 lines]
> | 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 - 29 Jan 2007 04:15 GMT
On Jan 28, 6:41 pm, "Daniel Pitts" <googlegrou...@coloraura.com>
wrote:

> > Hi All,
>
[quoted text clipped - 30 lines]
> 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 - 29 Jan 2007 06:59 GMT
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 28, 6:41 pm, "Daniel Pitts" <googlegrou...@coloraura.com>
> wrote:
[quoted text clipped - 34 lines]
> > 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 - 29 Jan 2007 15:32 GMT
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.

> So, what you mean is to convert every tertiary relationship to two
> relationships each in between two of the three entities?
[quoted text clipped - 41 lines]
> > > 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.