It all depends on what you are trying to do. Meaning, first figure
out what kind traversals you will need to do and then things will become
clearer.
One way of mapping things could be:
class Role {//..}
class Domain {//..}
class User{
private Set domainRoles;
//..
} class
DomainRole { private Role role;
private Domain domain;
//..
}
Note that you can change the structure of the relationship -
creating what I call "inversions". So you can have a DomainRole class, or a
UserRole, or a DomainUser class. Or all three. and have three separate mapping
elements in each hbm file. Also note that the choice of "Set" is my default way
of modeling collections. This might not be the semantics that you need. This is
easily changed!
<class name="User" table="user">
... <set role="domainRoles" table="user_domain_roles"> <key column="user_id"/> <composite-element class="DomainRole"> <many-to-one name="domain" class="Domain" column="domain_id"/> <many-to-one name="role" class="Role" column="role_id"/> </composite-element> </set> </class> Sandeep Dath
|
Title: Message
- [Hibernate] How to model this using hibernate? (OR mapping qu... Kenneth Foo
- Sandeep Dath