I have a rather strange many-many relationship I'm trying to model. There is extra data saved in the table for the many-many relationship. My solution was to create a class to represent the relationship and it's extra data. Logically I have Roles and ClassActions. Roles have a set of Permissions which are ClassAction + Denied. I cant seem to get my Permission instance to persist.
The relevant mappings are:
Permission.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="PR.BL" namespace="PR.BL.Manage.Security" >
<class name="PR.BL.Manage.Security.Permission, PR.BL" table="prmClassActionRoleOrUser">
<composite-id>
<key-many-to-one name="ClassAction" class="PR.BL.Manage.Security.ClassAction, PR.BL" column="ClassActionID" />
<key-many-to-one name="Role" class="PR.BL.Manage.Security.Role, PR.BL" column="RoleID" />
</composite-id>
<timestamp name="UpdateDT" column="UpdateDT"/>
<property name="Denied" column="Denied" type="Boolean" not-null="true" />
</class>
</hibernate-mapping>
Role.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="PR.BL" namespace="PR.BL.Manage.Security" >
<class name="PR.BL.Manage.Security.Role, PR.BL" table="prmRoles">
<id name="Id" column="RoleId" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<timestamp name="UpdateDT" column="UpdateDT"/>
<property name="Name" column="RoleName" type="string" length="255" not-null="true" />
<property name="Description" column="Description" type="string" length="255" not-null="false" />
<!--
<set name="Users" table="prmUsersInRoles">
<key column="RoleID" />
<many-to-many class="PR.BL.Manage.Security.User, PR.BL" column="UserID" />
</set>-->
<set name="Permissions" table="prmClassActionRoleOrUser" cascade="all">
<key column="RoleID" />
<one-to-many class="PR.BL.Manage.Security.Permission, PR.BL"/>
</set>
</class>
</hibernate-mapping>