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.  [ 1 post ] 
Author Message
 Post subject: Many-to-many relationship with intermediate table
PostPosted: Fri May 23, 2008 3:55 pm 
Newbie

Joined: Fri May 23, 2008 3:35 pm
Posts: 1
Hello,

I have three database tables: a web service table, a user table, and an access table, an intermediate table which links the web service table to the user table effectively creating a many-to-many relationship between web services and users. The purpose of the tables is to store which users have access to which web services.

I've created the mapping files as follows:

WebService:
Code:
...
<bag name="WebServiceAccess" lazy="false" cascade="all">
      <key column="WebServiceId" />
      <one-to-many class="MyDomain.WebServiceAccess,MyDomain" />
</bag>
...


WebServiceUser:
Code:
...
<bag name="WebServiceAccess" lazy="false" cascade="all">
      <key column="WebServiceUserId" />
      <one-to-many class="MyDomain.WebServiceAccess,MyDomain" />
</bag>
...


and WebServiceAccess, the intermediate table:
Code:
...
<many-to-one name="WebService" column="WebServiceId" cascade="all" lazy="false" not-null="true" />
<many-to-one name="WebServiceUser" column="WebServiceUserId" cascade="all" lazy="false" not-null="true" />
...


Is this the proper set-up? I am able to retrieve the users having access to a particular web service, but only one user ever gets returned, even if there are more than one. This suggests to me that the relationships in the mapping files are wrong (we're getting one instead of many), however I don't know how to correct them.

Also, I am not able to add a user to a web service (i.e., add a record to the user and access tables) or delete user/access records, again because I believe the mappings are wrong.

I've tried specifying inverse="true" in WebService and/or WebServiceUser. I've tried using many-to-many relationships in WebService and WebServiceUser, but the result was the same.

I've also tried removing the bag from web service user, and removing the WebService many-to-one relatonship from web service access, as I'm only interested in working with data in the web service - > web service access -> web service user direction, not the other way around... but that didn't work either.

If anyone knows how mapping files need to be set-up to support many-to-many relationships via intermediate join table, I would appreciate help!

Thank-you,
Leigh


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

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.