I am having trouble mapping the many to many relationship! I have a
Users table, Roles table and UserRoles table. A user can have many
roles. The Roles table just store the name of the roles like Admin,
Editor etc. The Userroles table stores the relationship of user with
the roles.

When I save the user the user information is saved but the Role
Information is not saved.

Here is my mappings:

<

?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
auto-import="true">
  <class name="EStudy.Business.Entities.User, EStudy.Business"
lazy="false" table="Users">
    <id name="Id" access="property" column="UserId">
      <generator class="native" />
    </id>

    <property name="FirstName" access="property" column="FirstName"/>
    <property name="LastName" access="property" column="LastName"/>

    <bag name="Roles" table="UserRoles" lazy="true">
      <key column="UserId"/>
      <many-to-many class="EStudy.Business.Entities.Role,
EStudy.Business" column="RoleId"/>
    </bag>
  </class>


  <class name="EStudy.Business.Entities.Role, EStudy.Business"
lazy="false" table="Roles">
    <id name="Id" access="property" column="RoleId">
      <generator class="native" />
    </id>

    <property name="RoleName" access="property" column="RoleName"/
>

    <bag name="Users" table="UserRoles" lazy="true" inverse="true">
      <key column="RoleId"/>
      <many-to-many class="EStudy.Business.Entities.User,
EStudy.Business" column="UserId"/>
    </bag>
  </class>


</hibernate-mapping>
The above mapping file is called User.hbm.xml and it contains the
mapping for User and Role and their relationship with the Userrole
table.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to