-->
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: Cant get Many-Many object to save.
PostPosted: Mon Jan 19, 2009 12:02 pm 
Newbie

Joined: Thu Jan 15, 2009 2:31 pm
Posts: 1
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>



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.