Java Persistence with Tertiary Relationship

Discussion in 'Java' started by Harry, Jan 26, 2007.

  1. Harry

    Harry Guest

    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
     
    Harry, Jan 26, 2007
    #1
    1. Advertising

  2. Harry

    Danno Guest

    On Jan 25, 9:59 pm, "Harry" <> 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
     
    Danno, Jan 28, 2007
    #2
    1. Advertising

  3. Harry

    Harry Guest

    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" <> wrote:
    > On Jan 25, 9:59 pm, "Harry" <> 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
     
    Harry, Jan 29, 2007
    #3
  4. Harry

    Daniel Pitts Guest

    On Jan 25, 8:59 pm, "Harry" <> 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.
     
    Daniel Pitts, Jan 29, 2007
    #4
  5. Harry

    Harry Guest

    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" <>
    wrote:
    > On Jan 25, 8:59 pm, "Harry" <> 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.
     
    Harry, Jan 29, 2007
    #5
  6. Harry

    Danno Guest

    On Jan 28, 7:07 pm, "Harry" <> 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, Jan 29, 2007
    #6
  7. Harry

    Danno Guest

    On Jan 28, 6:41 pm, "Daniel Pitts" <>
    wrote:
    > On Jan 25, 8:59 pm, "Harry" <> 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, Jan 29, 2007
    #7
  8. Harry

    Harry Guest

    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" <> wrote:
    > On Jan 28, 6:41 pm, "Daniel Pitts" <>
    > wrote:
    >
    >
    >
    > > On Jan 25, 8:59 pm, "Harry" <> 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, Jan 29, 2007
    #8
  9. Harry

    Danno Guest

    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" <> 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" <> wrote:
    >
    > > On Jan 28, 6:41 pm, "Daniel Pitts" <>
    > > wrote:

    >
    > > > On Jan 25, 8:59 pm, "Harry" <> 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, Jan 29, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper
    Replies:
    3
    Views:
    402
  2. Rick Osborn
    Replies:
    10
    Views:
    3,976
    Jon A. Cruz
    Feb 8, 2004
  3. javaguy44
    Replies:
    10
    Views:
    994
    Michael Berg
    May 18, 2004
  4. abcd

    Tertiary Operation

    abcd, Oct 17, 2006, in forum: Python
    Replies:
    10
    Views:
    1,721
    Fredrik Lundh
    Oct 17, 2006
  5. Kenneth P. Turvey

    Java Persistence API and persistence.xml

    Kenneth P. Turvey, Mar 15, 2008, in forum: Java
    Replies:
    2
    Views:
    17,403
    Kenneth P. Turvey
    Mar 16, 2008
Loading...

Share This Page