-->
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: Many-to-Many..Please Help!
PostPosted: Wed Aug 24, 2005 4:35 pm 
Newbie

Joined: Sun Jun 19, 2005 12:34 pm
Posts: 6
Hi!

I have been banging my head against this for two days now...
NHibernate throws "PropertyNotFoundException" and noting gets persisted to the db. What is the proper way of doing this? Please post a working solution for loading/saving many-to-many relations using a collection in the two domain objects.

Two classes:
Code:
class User {
int id;
string name;
IList roles;
}

class Role {
int id;
string name
IList users;
}


The database contains three tables: User, Role and UserRole for the many-to-many relationship..

My mappings:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="FirstNHibernate.Domain.User, FirstNHibernate" table="User">
      <id name="ID" column="Id" type="Int32" unsaved-value="0">
         <generator class="native" />
      </id>
      <property name="Name" column="Name" type="String" length="50"/>
      <bag name="Roles" table="UserRole" lazy="false">
         <key column="UserID" />
         <many-to-many column="RoleID" class="FirstNHibernate.Domain.Role, FirstNHibernate"  />
      </bag>
   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="FirstNHibernate.Domain.Role, FirstNHibernate" table="Role">
      <id name="Id" column="Id" type="Int32" unsaved-value="0">
         <generator class="native" />
      </id>
      <property name="Name" column= "Name" type="String" length="50"/>
      <bag name="Users" table="UserRole" inverse="true" lazy="true">
         <key column="RoleID" />
         <many-to-many column="UserID" class="FirstNHibernate.Domain.User, FirstNHibernate"  />
      </bag>
   </class>
</hibernate-mapping>



Regards
/Oscar


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.