Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8616823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:42:39+00:00 2026-06-12T05:42:39+00:00

TL;DR version: The code below gives me a Association references unmapped class exception when

  • 0

TL;DR version: The code below gives me a “Association references unmapped class” exception when building the SessionFactory. What should be changed in the code to fix it?


Even though Ayende @ Rahien doesn’t recommend using mappings to generic classes in this 2007 article I still had a go at it. I used the approach he mentioned. First the bit that is working:

<class name="Review`1[Person]" table="Review">
  <id name="Id" column="ReviewId"><generator class="native" /></id>
  <property name="Rating" />
  <many-to-one name="Subject" column="PersonId" class="Person" />
</class>

The corresponding generic class looks like this:

public class Review<T> : BaseEntity where T : IReviewable
{
    public virtual int Rating { get; set; }
    public virtual T Subject { get; set; }
}

This is working, and I can load these Review entities and show them in my MVC views no problem. The nice part is that my Subject will have the correct type when I use it in the controller and view.


However, when trying to map a collection of Review items on my Person class things start to break down. Here’s the mapping I’m currently using:

<class name="Person">
  <!-- abbreviated -->
  <bag name="Reviews" table="Review">
    <key column="PersonId"/>
    <one-to-many class="Review`1[Person]" />
    <!-- Also tried these:
    <one-to-many class="table="Review"> 
    ... plus a few variations with fully qualified names ...
    -->
  </bag>
</class>

With this (abbreviated) class:

public class Person : BaseEntity, IReviewable
{
    /* Abbreviated */
    public virtual IList<Review<Person>> Reviews { get; set; }
}

This ends with an exception while building the SessionFactory:

Association references unmapped class: ….insert one-to-many.class here….

So the question: What’s the problem here? Is this even possible? Should Ijust give up on mapping generic entities?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:42:40+00:00Added an answer on June 12, 2026 at 5:42 am

    Mapping-by-code generated this for me:

    <class name="NHTest.Review`1[[NHTest.Person, NHTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]" table="Review">
      ...
      <many-to-one name="Subject" column="..." />
    </class>
    <class name="Person">
      ...
      <bag name="Reviews">
        <key column="..." />
        <one-to-many class="NHTest.Review`1[[NHTest.Person, NHTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]" />
      </bag>
    </class>
    

    So, try with fully-qualified names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to implement a parallel version of the code below using threads
The code below is a simplified version of my website. On my site, the
a more exact version of the code is: class SomeParam; class IBase { public:
I have a sample code below. #include<iostream> template<typename T> class XYZ { private: T
the code here below: #!/usr/bin/env python import wx class MyForm(wx.Frame): def __init__(self): wx.Frame.__init__(self, None,
The piece of code below gives me the warning: Warning CS0618: MonoTouch.Dialog.Section.Add(System.Collections.Generic.IEnumerable<MonoTouch.Dialog.Element>)' is obsolete:
This code below gives me this error: You have an error in your SQL
I have configured, compiled a FFmpeg source code version 0.5 with versions as below:
Given the code below, wich is a very trimmed down version of the actual
I have the code below (a bare-bones version of Nehe tutorial 1 ported to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.