title: NHibernate.MappingException: An association from the table table refers to an unmapped class: Int32
body: <p>im starting whit Nhibernate and have managed to get a few examples working, but now the aplication im makin throws this exeption when Nhibernate load the configuration.</p>
  
  <pre><code>NHibernate.MappingException: An association from the table TBL_MARCADAS refers to an unmapped class: Int32
  at NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet done)
  at NHibernate.Cfg.Configuration.SecondPassCompile()
  at NHibernate.Cfg.Configuration.BuildSessionFactory()
  at BusinessLayer.entidad.inicializar() in D:\vault\BusinessLayer\entidad.vb:line 40
  at BusinessLayer.TblEmpleado.getEmpleado(String ci) in D:\vault\BusinessLayer\TblEmpleado.vb:line 60
  at BICWEBWS.Service1.get_minutosatraso(String str_CI) in D:\vault\BICWEBWS\App_Code\BICws.asmx.vb:line 7244
  </code></pre>
  
  <p>here is the entitiy</p>
  
  <pre><code>Imports System.Collections.Generic
  Imports System.Text
  Imports NHibernate.Collection
  Imports NHibernate.Mapping
  Imports Iesi.Collections
  
  &lt;NHibernate.Mapping.Attributes.Class(Table:="TBL_MARCADAS")&gt; _
  Public Class TblMarcadas
      Inherits entidad
      Private m_codgestion As Integer
      Private m_codperiodo As Integer
      Private m_coddiamarcada As Integer
      Private m_codempleado As Integer
      Private m_codhorario As Integer
      Private m_minAtrasos As Integer
      Private m_cantMarcadas As Integer
      Private m_horaUno As [String]
      Private m_horaDos As [String]
      Private m_horaTres As [String]
      Private m_horaCuatro As [String]
      Private m_horaCinco As [String]
      Private m_horaSeis As [String]
      Private m_diaLiteral As [String]
  
  
      Public Sub New()
          'MyBase.entidad()'
  
      End Sub
  
      &lt;NHibernate.Mapping.Attributes.CompositeId(0, class:="BusinessLayer.TblMarcadas, BusinessLayer")&gt; _
      &lt;NHibernate.Mapping.Attributes.KeyManyToOne(1, Name:="Codgestion", Column:="CODGESTION")&gt; _
      &lt;NHibernate.Mapping.Attributes.KeyManyToOne(2, Name:="Codperiodo", Column:="CODPERIODO")&gt; _
      &lt;NHibernate.Mapping.Attributes.KeyManyToOne(3, Name:="Coddiamarcada", Column:="CODDIAMARCADA")&gt; _
      &lt;NHibernate.Mapping.Attributes.KeyManyToOne(4, Name:="Codempleado", Column:="CODEMPLEADO")&gt; _
      Public Overridable Property Codgestion() As Integer
          Get
              Return m_codgestion
          End Get
          Set(ByVal value As Integer)
              m_codgestion = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property()&gt; _
      Public Overridable Property Codperiodo() As Integer
          Get
              Return m_codperiodo
          End Get
          Set(ByVal value As Integer)
              m_codperiodo = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property()&gt; _
      Public Overridable Property Coddiamarcada() As Integer
          Get
              Return m_coddiamarcada
          End Get
          Set(ByVal value As Integer)
              m_coddiamarcada = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property()&gt; _
      Public Overridable Property Codempleado() As Integer
          Get
              Return m_codempleado
          End Get
          Set(ByVal value As Integer)
              m_codempleado = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property()&gt; _
      Public Overridable Property Codhorario() As Integer
          Get
              Return m_codhorario
          End Get
          Set(ByVal value As Integer)
              m_codhorario = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property(Column:="MIN_ATRASOS")&gt; _
      Public Overridable Property MinAtrasos() As Integer
          Get
              Return m_minAtrasos
          End Get
          Set(ByVal value As Integer)
              m_minAtrasos = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property(Column:="CANT_MARCADAS")&gt; _
      Public Overridable Property CantMarcadas() As Integer
          Get
              Return m_cantMarcadas
          End Get
          Set(ByVal value As Integer)
              m_cantMarcadas = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property(Column:="HORA_UNO")&gt; _
      Public Overridable Property HoraUno() As [String]
          Get
              Return m_horaUno
          End Get
          Set(ByVal value As [String])
              m_horaUno = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property(Column:="HORA_DOS")&gt; _
      Public Overridable Property HoraDos() As [String]
          Get
              Return m_horaDos
          End Get
          Set(ByVal value As [String])
              m_horaDos = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property(Column:="HORA_TRES")&gt; _
      Public Overridable Property HoraTres() As [String]
          Get
              Return m_horaTres
          End Get
          Set(ByVal value As [String])
              m_horaTres = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property(Column:="HORA_CUATRO")&gt; _
      Public Overridable Property HoraCuatro() As [String]
          Get
              Return m_horaCuatro
          End Get
          Set(ByVal value As [String])
              m_horaCuatro = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property(Column:="HORA_CINCO")&gt; _
      Public Overridable Property HoraCinco() As [String]
          Get
              Return m_horaCinco
          End Get
          Set(ByVal value As [String])
              m_horaCinco = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property(Column:="HORA_SEIS")&gt; _
      Public Overridable Property HoraSeis() As [String]
          Get
              Return m_horaSeis
          End Get
          Set(ByVal value As [String])
              m_horaSeis = value
          End Set
      End Property
  
      &lt;NHibernate.Mapping.Attributes.Property(Column:="DIA_LITERAL")&gt; _
      Public Overridable Property DiaLiteral() As [String]
          Get
              Return m_diaLiteral
          End Get
          Set(ByVal value As [String])
              m_diaLiteral = value
          End Set
      End Property
  
  
      Public Overrides Function Equals(ByVal obj As [Object]) As Boolean
          Return MyBase.Equals(obj)
      End Function
  
      Public Overrides Function GetHashCode() As Integer
          Return MyBase.GetHashCode()
      End Function
  
      Public Overrides Function ToString() As String
          Dim s As [String] = ""
  
          s += "codgestion : " &amp; m_codgestion.ToString() &amp; vbLf
          s += "codperiodo : " &amp; m_codperiodo.ToString() &amp; vbLf
          s += "coddiamarcada : " &amp; m_coddiamarcada.ToString() &amp; vbLf
          s += "codempleado : " &amp; m_codempleado.ToString() &amp; vbLf
          s += "codhorario : " &amp; m_codhorario.ToString() &amp; vbLf
          s += "minAtrasos : " &amp; m_minAtrasos.ToString() &amp; vbLf
          s += "cantMarcadas : " &amp; m_cantMarcadas.ToString() &amp; vbLf
          If m_horaUno IsNot Nothing Then
              s += "horaUno : " &amp; m_horaUno.ToString() &amp; vbLf
          Else
              s += "horaUno : null" &amp; vbLf
          End If
          If m_horaDos IsNot Nothing Then
              s += "horaDos : " &amp; m_horaDos.ToString() &amp; vbLf
          Else
              s += "horaDos : null" &amp; vbLf
          End If
          If m_horaTres IsNot Nothing Then
              s += "horaTres : " &amp; m_horaTres.ToString() &amp; vbLf
          Else
              s += "horaTres : null" &amp; vbLf
          End If
          If m_horaCuatro IsNot Nothing Then
              s += "horaCuatro : " &amp; m_horaCuatro.ToString() &amp; vbLf
          Else
              s += "horaCuatro : null" &amp; vbLf
          End If
          If m_horaCinco IsNot Nothing Then
              s += "horaCinco : " &amp; m_horaCinco.ToString() &amp; vbLf
          Else
              s += "horaCinco : null" &amp; vbLf
          End If
          If m_horaSeis IsNot Nothing Then
              s += "horaSeis : " &amp; m_horaSeis.ToString() &amp; vbLf
          Else
              s += "horaSeis : null" &amp; vbLf
          End If
          If m_diaLiteral IsNot Nothing Then
              s += "diaLiteral : " &amp; m_diaLiteral.ToString() &amp; vbLf
          Else
              s += "diaLiteral : null" &amp; vbLf
          End If
          Return s
      End Function
  
      Public Overridable Function GetTotalAtrasos(ByVal mes As Integer, ByVal periodo As Integer, ByVal CI As String) As Integer
          ' That's how the Session decide to save or to update; set NHMA.Id(UnsavedValue=x) to replace 0
          Dim session As NHibernate.ISession
          Try
              session = _sessionFactory.OpenSession()
  
              Dim sd As System.Collections.IList = session.Find("from TBL_MARCADAS")
              Dim total As Integer
              For Each marcada As TblMarcadas In sd
                  total += marcada.MinAtrasos
              Next
              Return total
          Catch ex As Exception
  
          Finally
              If (session IsNot Nothing) Then
                  session.Close()
              End If
          End Try
      End Function
  
  
  End Class
  </code></pre>
  
  <p>and here is the table Script</p>
  
  <pre><code>CREATE TABLE [dbo].[TBL_MARCADAS](
   [CODGESTION] [int] NOT NULL,
   [CODPERIODO] [int] NOT NULL,
   [CODDIAMARCADA] [int] NOT NULL,
   [CODEMPLEADO] [int] NOT NULL,
   [CODHORARIO] [int] NULL,
   [MIN_ATRASOS] [int] NULL,
   [CANT_MARCADAS] [int] NULL,
   [HORA_UNO] [char](10) NULL,
   [HORA_DOS] [char](10) NULL,
   [HORA_TRES] [char](10) NULL,
   [HORA_CUATRO] [char](10) NULL,
   [HORA_CINCO] [char](10) NULL,
   [HORA_SEIS] [char](10) NULL,
   [DIA_LITERAL] [char](10) NULL,
  PRIMARY KEY CLUSTERED 
  (
   [CODGESTION] ASC,
   [CODPERIODO] ASC,
   [CODDIAMARCADA] ASC,
   [CODEMPLEADO] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  </code></pre>
  
  <p>this is what the NHibernate.mappings serializer throws:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!--Generated from NHibernate.Mapping.Attributes on 2010-06-24 08:27:58Z.--&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"&gt;
    &lt;class name="BusinessLayer.TblEmpleado, BusinessLayer" table="TBL_EMPLEADO"&gt;
      &lt;id name="codempleado"&gt;
        &lt;generator class="native" /&gt;
      &lt;/id&gt;
      &lt;property name="Nombre" /&gt;
      &lt;property name="ApellidoP" column="APELLIDO_P" /&gt;
      &lt;property name="ApellidoM" column="APELLIDO_M" /&gt;
      &lt;property name="FechaIngreso" column="FECHA_INGRESO" /&gt;
      &lt;property name="Cargo" /&gt;
      &lt;property name="SueldoActual" column="SUELDO_ACTUAL" /&gt;
      &lt;property name="Foto" /&gt;
      &lt;property name="Estadoempleado" /&gt;
      &lt;property name="Codregional" /&gt;
      &lt;property name="Codseguro" /&gt;
      &lt;property name="Codhorario" /&gt;
      &lt;property name="FechaNac" column="FECHA_NAC" /&gt;
      &lt;property name="Sexo" /&gt;
      &lt;property name="Ci" /&gt;
      &lt;property name="Expedido" /&gt;
      &lt;property name="Nacionalidad" /&gt;
      &lt;property name="TipoTrabajador" column="TIPO_TRABAJADOR" /&gt;
    &lt;/class&gt;
    &lt;class name="BusinessLayer.TblMarcadas, BusinessLayer" table="TBL_MARCADAS"&gt;
      &lt;composite-id class="TblMarcadas"&gt;
        &lt;key-many-to-one name="Codgestion" column="CODGESTION" /&gt;
        &lt;key-many-to-one name="Codperiodo" column="CODPERIODO" /&gt;
        &lt;key-many-to-one name="Coddiamarcada" column="CODDIAMARCADA" /&gt;
        &lt;key-many-to-one name="Codempleado" column="CODEMPLEADO" /&gt;
      &lt;/composite-id&gt;
      &lt;property name="Codperiodo" /&gt;
      &lt;property name="Coddiamarcada" /&gt;
      &lt;property name="Codempleado" /&gt;
      &lt;property name="Codhorario" /&gt;
      &lt;property name="MinAtrasos" column="MIN_ATRASOS" /&gt;
      &lt;property name="CantMarcadas" column="CANT_MARCADAS" /&gt;
      &lt;property name="HoraUno" column="HORA_UNO" /&gt;
      &lt;property name="HoraDos" column="HORA_DOS" /&gt;
      &lt;property name="HoraTres" column="HORA_TRES" /&gt;
      &lt;property name="HoraCuatro" column="HORA_CUATRO" /&gt;
      &lt;property name="HoraCinco" column="HORA_CINCO" /&gt;
      &lt;property name="HoraSeis" column="HORA_SEIS" /&gt;
      &lt;property name="DiaLiteral" column="DIA_LITERAL" /&gt;
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>thanks very much for your time</p>