NHibernate ignores the hbm.xml files

前端 未结 1 485
轻奢々
轻奢々 2021-01-17 05:59

I added a new table, .hbm.xml file and class to existing application. There is data from other tables as well displayed on the page.

For t

相关标签:
1条回答
  • 2021-01-17 06:26

    The similar issue as you, I have faced recently. And it was in VS 2012, where file re-naming works like, 1) selecting .hbm.xml file by clicking on it... 2) the part before file suffix is selected. 3) type new name, while suffix is unchanged.

    The trick is that NHibernate files, embedded resources, have two suffixes: .hbm.xml. The configuration like this:

    <mapping assembly="CaseMgr.Model" />
    

    Works with convention: search embedded resources with the extension .hbm.xml. So, if your new file is

    • MyNewFile.xml

    It must be

    • MyNewfile .hbm. xml

    the missing .hbm was in my case the reason, why NHibernate did not know about that file at all, and no exception was thrown if it was wrong... but it was not loaded and not available

    EXTENDED

    If I get your scenario correctly: One VS project(library), many .hbm.xml files, all are embedded resources, all are working but one.

    If I reproduce your issue correctly you should:

    run IL Spy to check that the dll contains all expected embedded resources
    run a test like:

    var factory = ... //get your NHibernate factory
    var entityType = typeof(CaseMgr.Model.BusinessObjects.PatLiverPeld);
    var persister = factory.GetClassMetadata(entityType) as AbstractEntityPersister;
    Assert.IsTrue(persister != null)
    

    In case that you'll see resource, and there is NO persister... try to move your mapping to existing working file (two classes in one .hbm.xml file). Any other case could hardly happen, because of missing exceptions during the "worng" config class mappings (as stated in the question)

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