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