-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-many question
PostPosted: Thu Nov 04, 2004 9:41 am 
Beginner
Beginner

Joined: Sun Dec 14, 2003 10:47 am
Posts: 23
I have a users and groups. A user can be in 0 to many groups and a group can have 0 to many users. Each association between group and user has an attribute (administrator).

I have tried using a composite-element as described here http://hibernate.org/118.html#A11

Where I created a UserGroupAssocation class that looked as follows

class UserGroupAssocation {

User user;
Group group;
boolean administrator;

}

class User {
Long uid;
String name;
Set groupAssociations;
}


class Group {
Long uid;
String name;
Set userAssociations;
}


create table user_groups (
group_uid BIGINT not null,
user_uid BIGINT not null,
administrator BIT
)


The problem is when hibernate loads the UserAssociations for a Group the group field is null and for a User the user field in the UserAssocaitons is null. Is there a simple fix to this?

Is there a better way to handle this mapping? Ultimately I need what I said in the first sentence? i.e. to be able to get the groups a user is in and know if that user is an administrator and for a group get the users in that group and know who the groups administrators are.


Here is the pertinent part of the mapping


Group.hbm.xml


<set name="userAssociations" table="user_groups" lazy="true" access='field'>
<key column="group_uid"/>
<composite-element class="UserGroupAssociation">
<many-to-one name='user' class='User' column='user_uid' not-null="true" access='field'/>
<property name='administrator' type='boolean' column='administrator' access='field'/>
</composite-element>
</set>




User.hbm.xml


<set name="groupAssociations" table="user_groups" lazy="true" access='field'>
<key column="user_uid"/>
<composite-element class="UserGroupAssociation">
<many-to-one name='group' class='Group' column='group_uid' not-null="true" access='field'/>
<property name='administrator' type='boolean' column='administrator' access='field'/>
</composite-element>
</set>


Top
 Profile  
 
 Post subject: fields null
PostPosted: Mon Nov 08, 2004 4:26 pm 
Newbie

Joined: Wed Oct 06, 2004 4:39 pm
Posts: 17
I have a similar problem. Does anybody have any solution?

Thanks.-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.