Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An association from the table Y refers to an unmapped class: Y - C# NHibernate

I'm getting the exception:

"An association from the table order refers to an unmapped class: FrancosPoS.DBMapping.pastaCombo"

for this NHibernate mapping:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="FrancosPoS" namespace="FrancosPoS.DBMapping" xmlns="urn:nhibernate-mapping-2.2">
  <class name="order" table="order" lazy="true" >
    <id name="idOrder">
      <generator class="identity" />
    </id>
    <many-to-one insert="false" update="false" lazy="false" name="idPastaI" class="FrancosPoS.DBMapping.pastaIndividual">
      <column name="idPastaI" sql-type="int(11)" not-null="false" />
    </many-to-one>
    <!--<property name="idPastaI">
      <column name="idPastaI" sql-type="int(11)" not-null="false" />
    </property>-->
    <many-to-one insert="false" update="false" lazy="false" name="pastaCombo" class="FrancosPoS.DBMapping.pastaCombo">
      <column name="idPastaC" sql-type="int(11)" not-null="false" />
    </many-to-one>
    <!--<property name="idPastaC">
      <column name="idPastaC" sql-type="int(11)" not-null="false" />
    </property>-->
    <many-to-one insert="false" update="false" lazy="false" name="idPastaF" class="FrancosPoS.DBMapping.pastaFeast">
      <column name="idPastaF" sql-type="int(11)" not-null="false" />
    </many-to-one>
    <!--<property name="idPastaF">
      <column name="idPastaF" sql-type="int(11)" not-null="false" />
    </property>-->
    <many-to-one insert="false" update="false" lazy="false" name="idSalad" class="FrancosPoS.DBMapping.salad">
      <column name="idSalad" sql-type="int(11)" not-null="false" />
    </many-to-one>
    <!--<property name="idSalad">
      <column name="idSalad" sql-type="int(11)" not-null="false" />
    </property>-->
    <many-to-one insert="false" update="false" lazy="false" name="idDrink" class="FrancosPoS.DBMapping.drink">
      <column name="idDrink" sql-type="int(11)" not-null="false" />
    </many-to-one>
    <!--<property name="idDrink">
      <column name="idDrink" sql-type="int(11)" not-null="false" />
    </property>-->
    <property name="price">
      <column name="price" sql-type="decimal(8,4)" not-null="true" />
    </property>
    <property name="cash">
      <column name="cash" sql-type="tinyint(1)" not-null="false" />
    </property>
    <property name="credit">
      <column name="credit" sql-type="tinyint(1)" not-null="false" />
    </property>
    <property name="obs">
      <column name="obs" sql-type="varchar(150)" not-null="true" />
    </property>
  </class>
</hibernate-mapping>

and this is my cs class:

namespace FrancosPoS.DBMapping {

    public partial class order {
        public order() { }
        public virtual int idOrder { get; set; }
        public virtual pastaIndividual pastaIndividual { get; set; }
        public virtual pastaCombo pastaCombo { get; set; }
        public virtual pastaFeast pastaFeast { get; set; }
        public virtual salad salad { get; set; }
        public virtual drink drink { get; set; }
        public virtual string price { get; set; }
        public virtual System.Nullable<int> cash { get; set; }
        public virtual System.Nullable<int> credit { get; set; }
        public virtual string obs { get; set; }
    }
}

pastaCombo mapping:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="FrancosPoS" namespace="FrancosPoS.DBMapping" xmlns="urn:nhibernate-mapping-2.2">
  <class name="pastaCombo" table="pasta_combo" lazy="true" >
    <id name="idPastaC">
      <generator class="identity" />
    </id>
    <property name="type">
      <column name="type" sql-type="varchar(25)" not-null="true" />
    </property>
    <property name="price">
      <column name="price" sql-type="decimal(8,4)" not-null="true" />
    </property>
    <property name="freeDrink">
      <column name="freeDrink" sql-type="smallint(5) unsigned" not-null="true" />
    </property>
    <property name="freeSalad">
      <column name="freeSalad" sql-type="smallint(5) unsigned" not-null="true" />
    </property>
  </class>
</hibernate-mapping>

pastaCombo class:

namespace FrancosPoS.DBMapping {

    public class pastaCombo {
        public pastaCombo() { }
        public virtual int idPastaC { get; set; }
        public virtual string type { get; set; }
        public virtual string price { get; set; }
        public virtual int freeDrink { get; set; }
        public virtual int freeSalad { get; set; }
    }
}

What am I missing?

Sincerely,

PS.: The properties are commented because I (think that I) don't need them as my class has the object type, not the int ID. If I use it NHibernate throw the error of "trying to set property type by reflection".

EDIT: Included pastaCombo mapping and class.

like image 401
gbc921 Avatar asked Apr 26 '12 05:04

gbc921


1 Answers

I just experienced the same error:

An association from the table <table name> refers to an unmapped class: <my entity class>

And the only solution that solved my issue is to add .hbm on the mapping file where in your filename should be in this format: <filename>.hbm.xml

like image 103
Rei A. Banaag Avatar answered Oct 04 '22 01:10

Rei A. Banaag