-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Complex Map
PostPosted: Tue Sep 23, 2008 6:42 am 
Newbie

Joined: Tue Sep 23, 2008 5:59 am
Posts: 3
Hi,

I have a model where there is a relationship between users and roles but the roles are determined by firm. So for example a user u1 is associated with firm f1 and have roles r1, r2. The same user u1 could also be associated with f2 and u1 would have roles r3, r4 for that relationship. In Java I would like to map this as a Map<Firm, List<Role>> from the User class. Is this possible and how can it be done?

Many Thanks in advance

Ted


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 6:12 am 
Newbie

Joined: Wed May 21, 2008 11:21 am
Posts: 11
I'm not very sure, but probably something like this:

Code:
<class name="TFirm" table="firms">
     <id name="id" />
  </class>
 
  <class name="TRole" table="roles">
     <id name="id" />
  </class>
 
  <class name="TUser" table="users">
     <id name="id" />
     <map name="roles" table="users_roles">
       <key column="user_id" />
       <index-many-to-many column="firm_id" class="TFirm" />
       <many-to-many column="role_id" class="TRole"></many-to-many>
     </map>     
  </class>


This might help you http://ndpsoftware.com/HibernateMappingCheatSheet.html

Another solution would be to have the RoleInFirm intermediary class used to encode/decode Map<Firm, List<Role>>.

Hope it helps...


Top
 Profile  
 
 Post subject: Ternary associations
PostPosted: Thu Sep 25, 2008 3:26 am 
Newbie

Joined: Tue Sep 23, 2008 5:59 am
Posts: 3
Thanks Cristian, it turns out that you can't map collections of collections so instead I created link table as a first class object, one for each user/firm combination, and created a many to many link between this and the roles table (via another join table).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.