-->
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: ICriteria using the associative many-to-many
PostPosted: Fri Sep 22, 2006 2:15 pm 
Newbie

Joined: Fri Apr 01, 2005 5:20 pm
Posts: 14
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>



RoleForm
Code:
<?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>

Menu
Code:
<?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>

_________________
Thanks,

John


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.