title: NHibernate many to many mapping error - NHibernate.MappingException: Could not determine type for:
body: <p>I am having a problem when trying create a many to many mapping.  Consider the following tables:</p>
  
  <pre><code>CREATE TABLE [dbo].[student]
  (
      [Id]            INT             IDENTITY (1, 1) NOT NULL,
      [Name]          NVARCHAR(255)   NOT NULL,
      -- Some other stuff...      
  )
  
  CREATE TABLE [dbo].[Subject]
  (
      [Id]            INT             IDENTITY (1, 1) NOT NULL,
      [Name]  NVARCHAR (50)   NOT NULL,
  
      -- Some other stuff...
  )
  
  CREATE TABLE [dbo].[studentToSubject]
  (
      [studentId] INT NOT NULL,
      [subjectId]     INT NOT NULL,
  )
  </code></pre>
  
  <p>The interesting part of my student mapping file looks like this:</p>
  
  <pre><code>&lt;id name="Id" type="Int32"&gt;
        &lt;column name="Id" sql-type="int" not-null="true" unique="true"/&gt;
        &lt;generator class="native" /&gt;
      &lt;/id&gt;
  
        &lt;property name="Name" not-null="true" /&gt;
        &lt;bag name="subjects" table="studentToSubject"&gt;
            &lt;key column="studentId"&gt;&lt;/key&gt;
            &lt;many-to-many column="subjectId" class="subject" /&gt;
        &lt;/bag&gt;
  </code></pre>
  
  <p>I want to end up with a student with a collection of their subjects.  However, I get an error:</p>
  
  <pre><code>NHibernate.MappingException: Could not determine type for: MyApp.Domain.Subject, MyApp.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=865c2d2b185d0c4b, for columns: NHibernate.Mapping.Column(studentId).
  </code></pre>
  
  <p>I have seen some examples of this type of mapping, but they differ in the fact that their Id columns have name that match the mapping table name, for example their Id column in the student table is called 'studentId'.  I cannot do this (it has to be Id) but I think this is the cause of the problem.</p>
  
  <p>Thanks</p>