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: Mapping for General Association
PostPosted: Tue Oct 06, 2009 11:09 am 
Newbie

Joined: Tue Oct 06, 2009 10:42 am
Posts: 1
Hello,

I'm still fairly new to NHibernate, and we are attempting to build an application which allows many-to-many associations between several entities. My question is, what's the best way to accomplish this in the mapping? Has anyone else tried this or can direct me to a sample app with similar parameters?

Below, I'll attempt the describe the key areas of what we have. So far, I've found that I have to use not-found="ignore" because NHibernate enforces referential integrity. Also, using the cascade features seem unreliable for updates in this situation (possibly due to my mappings). Right now, I create and insert each object and then create and insert the association, and this works fine. But I would prefer to use the cascade features if I could.

Thanks in advance for your help.

Here's the table structure. It's hosted on MSSQL2005. All Id fields are GUID's:

[Association]
ParentId
ChildId

[Person]
Id

[Location]
Id

[Document]
Id


Each POCO classes looks something like this:

class Person{
Guid Id {get;set;}
IList<Person> Persons {get;private set}
IList<Location> Locations {get;private set}
IList<Document> Documents{get;private set}
}


Below is a mapping file for the Person entity:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model.DAO">
<class name="Person">
<id name="Id" type="System.Guid" column="Id">
<generator class="guid.native"/>
</id>

<bag name="Persons" table="Association">
<key column="ParentId"/>
<many-to-many class="Person" column="ChildId" not-found="ignore">
</bag>

<bag name="Locations" table="Association" cascade="none">
<key column="ParentId"/>
<many-to-many class="Location" column="ChildId" not-found="ignore"/>
</bag>

<bag name="Documents" table="Association" cascade="none">
<key column="ParentId" />
<many-to-many class="Document" column="ChildId" not-found="ignore"/>
</bag>


</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.