Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Duplicate class/entity mapping problem

Tags:

c#

nhibernate

I've have started my foray into C#.NET and NHibernate and I'm finally stuck on an exception I can't seem to figure out, and Google isn't helping.

I'm getting a "NHibernate.DuplicateMappingException : Duplicate class/entity mapping" on my Parent class. Below is my mapping file for the Parent class, and the Youth class that uses the Parent class:

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                       assembly="Surrix.Cerberus.YouthData"
                       namespace="Surrix.Cerberus.YouthData.Domain">
      <class name="Parent">
        <id name="parentId">
          <generator class="guid" />
        </id>
        <property name="firstName" not-null="true" />
        <property name="lastName" not-null="true" />
        <property name="homePhone" />
        <property name="parentEmail" />
        <property name="relationshipToYouth" />
        
        <!-- Address component that should map to the Address class -->
        <component name="parentAddress">
          <property name="street" />
          <property name="state" />
          <property name="zipCode" />
          <property name="city" />
        </component>
        
      </class>
    
    </hibernate-mapping>

And here is the relevant part of the Youth class (it is considerably bigger)

    <set name="YouthParents" table="YouthParents" cascade="none">
      <key column="youthId" />
      <many-to-many column="parentId" class="Parent"/>
    </set>

Only other thing is the Youth class also has the firstName and lastName properties, but I can't see that being a problem.

like image 332
Patrick McDaniel Avatar asked Nov 28 '22 04:11

Patrick McDaniel


1 Answers

Make sure you are not doing both of these 2 things.

(1) adding the assembly in code:

// Code Configuration
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(Employee).Assembly); 
// Presuming Employee resides in "MyAssembly" as seen below.

(2) And then also adding the assembly in the config file:

<!-- .config configuration -->
<session-factory>
     <!-- bunch of other stuff -->
    <mapping assembly="MyAssembly"/> <!-- as in MyAssembly.dll -->
</session-factory>
like image 56
granadaCoder Avatar answered Dec 05 '22 18:12

granadaCoder