NHibernate.MappingException: No persister for: XYZ

后端 未结 16 1063
天命终不由人
天命终不由人 2020-12-01 03:24

Now, before you say it: I did Google and my hbm.xml file is an Embedded Resource.

Here is the code I am calling:

相关标签:
16条回答
  • 2020-12-01 03:41

    Sounds like you forgot to add a mapping assembly to the session factory configuration..

    If you're using app.config...

    .
    .
        <property name="show_sql">true</property>
        <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
        <mapping assembly="Project.DomainModel"/>  <!-- Here -->
    </session-factory>
    .
    .
    
    0 讨论(0)
  • 2020-12-01 03:42

    I had the same problem because I was adding the wrong assembly in Configuration.AddAssembly() method.

    0 讨论(0)
  • 2020-12-01 03:43

    I got this off of here:

    In my case the mapping class was not public. In other words, instead of:

    public class UserMap : ClassMap<user>  // note the public!
    

    I just had:

    class UserMap : ClassMap<user>
    
    0 讨论(0)
  • 2020-12-01 03:43

    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.

    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)

    0 讨论(0)
  • 2020-12-01 03:44

    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.

    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<YourEntityClassName>())
    
    0 讨论(0)
  • 2020-12-01 03:47

    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 cfg.AddAssembly(... to add assembly #2 (instead of assembly #1) and everything worked. Thanks!

    0 讨论(0)
提交回复
热议问题