Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: Build 1.0.2.0
Hi,
I have a many-to-many relationship and it works great. Below are the mappings. I have a Role to Menu relationship and Role also goes to Form using the same table. The RoleForm associative table in the middle is also an object table. In addtion to holding the relationship it also holds the role data for each form.
I can start with the a role object and get the menus property from it with no problem, but I would also like to build an ICriteria query that will get the menus based on some of the data in the associative table/object.
For instance I would like all the menus for Role1 where NoAccess == false.
I did not include the c# files for the objects, but they are just the standard object with the properties listed in the hbm.xml files.
Any thoughts on this?
Thanks,
John
Role
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DTP.Data.Role,DTP" table="Role">
<id name="Id" column="RoleID" type="Int64">
<generator class="native"/>
</id>
<bag name="DtpUserList" inverse="true" lazy="true" >
<key column="RoleID" />
<one-to-many class="DTP.Data.DtpUser,DTP" />
</bag>
<bag name="RoleFormList" inverse="true" lazy="true" >
<key column="RoleID" />
<one-to-many class="DTP.Data.RoleForm,DTP" />
</bag>
<bag name="MenuList" lazy="true" cascade="none" table="RoleForm">
<key column="RoleID"></key>
<many-to-many class="DTP.Data.Menu, DTP" column="FormID"></many-to-many>
</bag>
<property column="RoleName" type="String" name="RoleName" not-null="true" length="30" />
</class>
</hibernate-mapping>
RoleFormCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DTP.Data.RoleForm,DTP" table="RoleForm">
<id name="Id" column="RoleForm_ID" type="Int64">
<generator class="native"/>
</id>
<many-to-one name = "Role" column="RoleID" class="DTP.Data.Role,DTP"/>
<many-to-one name = "Form" column="FormID" class="DTP.Data.ProTracForm,DTP"/>
<property column="FullAccess" type="boolean" name="FullAccess" not-null="true" />
<property column="EditP" type="boolean" name="Edit" not-null="true" />
<property column="AddP" type="boolean" name="Add" not-null="true" />
<property column="DeleteP" type="boolean" name="Delete" not-null="true" />
<property column="NoAccess" type="boolean" name="NoAccess" not-null="true" />
</class>
</hibernate-mapping>
MenuCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DTP.Data.Menu,DTP" table="Menu">
<id name="Id" column="ItemID" type="Int64" >
<generator class="native"/>
</id>
<many-to-one name="MenuGroup" column="MenuGroupID" class="DTP.Data.MenuGroup,DTP" />
<property column="Description" name="Description" not-null="true" length="50" />
<property column="SortOrder" name="SortOrder" />
<property column="Type" name="Type" not-null="true" length="50" />
<property column="ItemName" name="ItemName" length="50" />
<many-to-one name="ProTracForm" unique="true" column="FormID" class="DTP.Data.ProTracForm,DTP" />
</class>
</hibernate-mapping>