<p>Now, before you say it: I <strong>did</strong> Google and my <code>hbm.xml</code> file <strong>is</strong> an Embedded Resource. </p>

<p>Here is the code I am calling:</p>

<pre><code>ISession session = GetCurrentSession();
var returnObject =  session.Get&lt;T&gt;(Id);
</code></pre>

<p>Here is my mapping file for the class:</p>

<pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt;
  &lt;class name="HQData.Objects.SubCategory, HQData" table="SubCategory" lazy="true"&gt;
    &lt;id name="ID" column="ID" unsaved-value="0"&gt;
      &lt;generator class="identity" /&gt;
    &lt;/id&gt;

    &lt;property name="Name" column="Name" /&gt;
    &lt;property name="NumberOfBuckets" column="NumberOfBuckets"  /&gt;
    &lt;property name="SearchCriteriaOne" column="SearchCriteriaOne" /&gt;

    &lt;bag name="_Businesses" cascade="all"&gt;
      &lt;key column="SubCategoryId"/&gt;
      &lt;one-to-many 
         class="HQData.Objects.Business, HQData"/&gt;
    &lt;/bag&gt;

    &lt;bag name="_Buckets" cascade="all"&gt;
      &lt;key column="SubCategoryId"/&gt;
      &lt;one-to-many
         class="HQData.Objects.Bucket, HQData"/&gt;
    &lt;/bag&gt;

  &lt;/class&gt;
&lt;/hibernate-mapping&gt;
</code></pre>

<p>Has anyone run to this issue before?</p>

<p>Here is the full error message:</p>

<blockquote>
<pre>MappingException: No persister for:  HQData.Objects.SubCategory]NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName, Boolean throwIfNotFound)
 in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Impl\SessionFactoryImpl.cs:766 NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName)
 in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Impl\SessionFactoryImpl.cs:752 NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType)
 in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Event\Default\DefaultLoadEventListener.cs:37 NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType)
 in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Impl\SessionImpl.cs:2054 NHibernate.Impl.SessionImpl.Get(String entityName, Object id)
 in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Impl\SessionImpl.cs:1029 NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id)
 in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Impl\SessionImpl.cs:1020 NHibernate.Impl.SessionImpl.Get(Object id)
 in c:\CSharp\NH2.0.0\nhibernate\src\NHibernate\Impl\SessionImpl.cs:985 HQData.DataAccessUtils.NHibernateObjectHelper.LoadDataObject(Int32 Id)
 in C:\Development\HQChannelRepo\HQ Channel Application\HQChannel\HQData\DataAccessUtils\NHibernateObjectHelper.cs:42 HQWebsite.LocalSearch.get_subCategory()
 in C:\Development\HQChannelRepo\HQ Channel Application\HQChannel\HQWebsite\LocalSearch.aspx.cs:17 HQWebsite.LocalSearch.Page_Load(Object sender, EventArgs e)
 in C:\Development\HQChannelRepo\HQ Channel Application\HQChannel\HQWebsite\LocalSearch.aspx.cs:27 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436</pre>
</blockquote>

<p><strong>Update</strong>, here's what the solution for <em>my</em> scenario was: I had changed some code and I wasn't adding the Assembly to the config file during runtime. </p>

[{'answer_id': 57860, 'author': 'Matt Hinze', 'author_id': 2676, 'author_profile': 'https://Stackoverflow.com/users/2676', 'pm_score': 2, 'selected': False, 'text': '<p>Should it be <code>name="Id"</code>?  Typos are a likely cause.</p>\n\n<p>Next would be to try it out with a non-generic test to make sure you\'re passing in the proper type parameter.</p>\n\n<p>Can you post the entire error message?</p>\n'}, {'answer_id': 57995, 'author': 'Andy S', 'author_id': 3759, 'author_profile': 'https://Stackoverflow.com/users/3759', 'pm_score': 8, 'selected': True, 'text': '<p>Sounds like you forgot to add a mapping assembly to the session factory configuration..</p>\n\n<p>If you\'re using app.config...</p>\n\n<pre><code>.\n.\n    &lt;property name="show_sql"&gt;true&lt;/property&gt;\n    &lt;property name="query.substitutions"&gt;true 1, false 0, yes \'Y\', no \'N\'&lt;/property&gt;\n    &lt;mapping assembly="Project.DomainModel"/&gt;  &lt;!-- Here --&gt;\n&lt;/session-factory&gt;\n.\n.\n</code></pre>\n'}, {'answer_id': 615156, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>If running tests on the repository from a seperate assembly, then make sure your Hibernate.cfg.xml is set to output always in the bin directory of said assembly. This wasn't happening for us and we got the above error in certain circumstances.</p>\n\n<p>Disclaimer: This might be a slightly esoteric bit of advice, given that it's a direct result of how we structure our repository integration test assemblies (i.e. we have a symbolic link from each test assembly to a single Hibernate.xfg.xml)</p>\n"}, {'answer_id': 660099, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Had a similar problem when find an object by id...\nAll i did was to use the fully qualified name in the class name. That is \nBefore it was :</p>\n\n<pre><code>find("Class",id)\n</code></pre>\n\n<p>Object so it became like this : </p>\n\n<pre><code>find("assemblyName.Class",id)\n</code></pre>\n'}, {'answer_id': 1795914, 'author': 'Chris Vosnidis', 'author_id': 166576, 'author_profile': 'https://Stackoverflow.com/users/166576', 'pm_score': 7, 'selected': False, 'text': "<p>Something obvious, yet quite useful for someone new to NHibernate.</p>\n\n<p>All XML Mapping files should be treated as <em>Embedded Resources</em> rather than the default <em>Content</em>. This option is set by editing the Build Action attribute in the file's properties.</p>\n\n<p>XML files are then embedded into the assembly, and parsed at project startup during NHibernate's configuration phase.</p>\n"}, {'answer_id': 2421598, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>Don't forget to specify mapping information in .config file</p>\n\n<p>e.g. </p>\n\n<p>where MyApp.Data is assembly that contains your mappings</p>\n"}, {'answer_id': 3203836, 'author': 'David', 'author_id': 386675, 'author_profile': 'https://Stackoverflow.com/users/386675', 'pm_score': 2, 'selected': False, 'text': '<p>I had similar problem, and I solved it as folows:</p>\n\n<p>I working on MS SQL 2008, but in the NH configuration I had bad dialect:\nNHibernate.Dialect.<strong>MsSql2005Dialect</strong>\nif I correct it to:\nNHibernate.Dialect.<strong>MsSql2008Dialect</strong>\nthen everything\'s working fine without a exception "No persister for: ..."\nDavid.</p>\n'}, {'answer_id': 3512745, 'author': 'nHibernate User', 'author_id': 424070, 'author_profile': 'https://Stackoverflow.com/users/424070', 'pm_score': 6, 'selected': False, 'text': '<p>My issue was that I forgot to put the .hbm in the name of the mapping xml.  Also make sure you make it an embedded resource!</p>\n'}, {'answer_id': 3542235, 'author': 'basarat', 'author_id': 390330, 'author_profile': 'https://Stackoverflow.com/users/390330', 'pm_score': 6, 'selected': False, 'text': '<p>I got this off of <a href="http://www.mail-archive.com/fluent-nhibernate@googlegroups.com/msg03276.html" rel="noreferrer">here</a>:</p>\n\n<p>In my case the mapping class was not public. In other words, instead of:</p>\n\n<pre><code>public class UserMap : ClassMap&lt;user&gt;  // note the public!\n</code></pre>\n\n<p>I just had:</p>\n\n<pre><code>class UserMap : ClassMap&lt;user&gt;\n</code></pre>\n'}, {'answer_id': 4538190, 'author': 'IdontCareAboutReputationPoints', 'author_id': 554893, 'author_profile': 'https://Stackoverflow.com/users/554893', 'pm_score': 2, 'selected': False, 'text': '<p>I had the same problem because I was adding the wrong assembly in Configuration.AddAssembly() method.</p>\n'}, {'answer_id': 6112707, 'author': 'Seth', 'author_id': 521662, 'author_profile': 'https://Stackoverflow.com/users/521662', 'pm_score': 2, 'selected': False, 'text': "<p>I was also adding the wrong assembly during initialization. The class I'm persisting is in assembly #1, and my .hbm.xml file is embedded in assembly #2. I changed <code>cfg.AddAssembly(...</code> to add assembly #2 (instead of assembly #1) and everything worked. Thanks!</p>\n"}, {'answer_id': 7360026, 'author': 'Amol', 'author_id': 189654, 'author_profile': 'https://Stackoverflow.com/users/189654', 'pm_score': 0, 'selected': False, 'text': '<p>Make sure you have called the <code>CreateCriteria(typeof(DomainObjectType))</code> method on Session for the domain object which you intent to fetch from DB.</p>\n'}, {'answer_id': 11252936, 'author': 'goku_da_master', 'author_id': 151325, 'author_profile': 'https://Stackoverflow.com/users/151325', 'pm_score': 2, 'selected': False, 'text': "<p>To add to Amol's answer, don't make the mistake of specifying the Interface class type.  <b>Make sure you specify the implementation class</b>.  (Ie. don't use IDomainObjectType). Not that I made this mistake... :)</p>\n"}, {'answer_id': 11758228, 'author': 'Nickmaovich', 'author_id': 565157, 'author_profile': 'https://Stackoverflow.com/users/565157', 'pm_score': 5, 'selected': False, 'text': "<p>Spending about 4 hours on <strong>googling</strong> and <strong>stackoverflowing</strong>, trying all of stuff around there, i've found my error:</p>\n\n<p><strong>My mapping file was called <em>.nbm.xml</em> instead of <em>.hbm.xml</em></strong>. That was insane.</p>\n"}, {'answer_id': 23153675, 'author': 'Arkadas Kilic', 'author_id': 3276913, 'author_profile': 'https://Stackoverflow.com/users/3276913', 'pm_score': 2, 'selected': False, 'text': '<p>This error occurs because of invalid mapping configuration. You should check where you set .Mappings for your session factory. Basically search for ".Mappings(" in your project and make sure you specified correct entity class in below line.</p>\n\n<pre><code>.Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;YourEntityClassName&gt;())\n</code></pre>\n'}, {'answer_id': 60490552, 'author': 'Robetto', 'author_id': 3631770, 'author_profile': 'https://Stackoverflow.com/users/3631770', 'pm_score': 0, 'selected': False, 'text': '<p>I have a similar problem but all mentioned <em>requirements</em> are met. In my case I try to save some entity class (Type of OBJEKTE) back to the DB. Other places do work but only in this case it fails and raises this exception.</p>\n\n<p>My solution (HACK) was to re-map the objet of type OBJEKTE again and store it then. Suddenly it works. But don\'t ask why. </p>\n\n<pre><code>            OBJEKTE t = _mapper.Map&lt;OBJEKTE&gt;(inparam);\n            OBJEKTE res = await _objRepo.UpdateAsync(t);\n</code></pre>\n\n<p>If inparam would go straight to UpdateAsync() it cannot find a matching persistor.</p>\n\n<p>It could be explained by the way NH does this. It derives a proxy from your mapping class and implements the properties with dirty handling included. See this:</p>\n\n<pre><code>t.GetType()\n{Name = "OBJEKTE" FullName = "MyComp.Persistence.OBJEKTE"}\n\ninparam.GetType()\n{Name = "OBJEKTEProxyForFieldInterceptor" FullName = "OBJEKTEProxyForFieldInterceptor"}\n</code></pre>\n\n<p>The fun thing though is that the source of <code>inparam</code> is in fact the NH repository itself. Anyways. I stay with this reassign hack for the next time being.</p>\n'}, {'answer_id': 65218643, 'author': 'xhafan', 'author_id': 379279, 'author_profile': 'https://Stackoverflow.com/users/379279', 'pm_score': 0, 'selected': False, 'text': "<p>I my case I fetched an entity without <code>await</code>:</p>\n<pre><code>var company = _unitOfWork.Session.GetAsync&lt;Company&gt;(id);\n</code></pre>\n<p>and then I tried to delete it:</p>\n<pre><code>await _unitOfWork.Session.DeleteAsync(company);\n</code></pre>\n<p>I could not decipher the error message that I'm deleting a <code>Task&lt;Company&gt;</code> instead of <code>Company</code>:</p>\n<p><em>MappingException: No persister for: System.Runtime.CompilerServices.AsyncTaskMethodBuilder'1+AsyncStateMachineBox'1[[SmartGuide.Core.Domain.Users.Company, SmartGuide.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null],[NHibernate.Impl.SessionImpl+d__54`1[[SmartGuide.Core.Domain.Users.Company, SmartGuide.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]], NHibernate, Version=5.3.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4]]</em></p>\n"}, {'answer_id': 71228041, 'author': 'Mitja', 'author_id': 1651498, 'author_profile': 'https://Stackoverflow.com/users/1651498', 'pm_score': 0, 'selected': False, 'text': "<p>You would think that after 14 years, all possible answers to this question have been written down. It seems like that is not the case.</p>\n<p>In the application I'm currently working on, there are <em>several</em> <code>ISessionFactory</code> instances, each one for a different database.</p>\n<p>If you're taking the wrong one to create your <code>ISession</code>, of course it will have no idea of the class you're trying to persist, which was the error in my case.</p>\n"}]
['https://Stackoverflow.com/questions/57804', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4140/']