2009-09-16 50 views
1

我想让NHibernate工作。我有这个类:NHibernate MappingException。没有Persister

mm.k.Domain.Kampagne 

空间(namespace /组件mm.k.Domain)

在另一个Visual Studio项目(大会mm.k.Infrastructure)我得到了我的映射文件(在Mappings目录),我的hibernate.cfg.xml和一些存储库。

我的继承人映射文件:

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
        assembly="mm.k.Domain" 
        namespace="mm.k.Domain"> 

    <class name="Kampagne" table="Kampagner"> 
    <id name="Id"> 
     <generator class="identity" /> 
    </id> 
    <property name="Navn" not-null="true" /> 
    <property name="Logo" /> 
    </class> 

</hibernate-mapping> 

当我配置我的会议,我这样做:

_configuration.AddAssembly(typeof(mm.k.Domain.Kampagne).Assembly); 

而且那是什么不行! 当调用:

var test = session.Get<Kampagne>(kampagneId); 

我得到以下错误: “没有留存为:mm.k.Domain.Kampagne” 不管你喜欢不注册嵌入式映射FILD。请注意,我已将映射文件设置为Embedded Resource的构建操作。

如果我改变上述行来:

_configuration.AddFile(@"fullpath\mm.k.Infrastructure\Mappings\Kampagne.hbm.xml"); 

一切工作完全正常!

任何想法?提前致谢。

回答

3

不知道你nhibernate.cfg.xml文件看起来像什么,但我通常有你给根据您的信息,这样

<mapping assembly="mm.K.Infrastructure"/> 

的项目。 NHibernate使用它从这个特定的程序集加载映射文件。

这应该给你你需要的映射。

+0

这样做的伎俩。谢谢!奇怪NHibernate入门教程没有提到这个? – 2009-09-21 18:59:32

7

如果有人会像我那样用Hibernate.NET来解决这个问题。 确保您在属性窗口中为您的文件构建操作选择了“嵌入式资源”

+0

完美的,这对我来说,不像其他答案在这里。尼斯。 – thomas 2013-10-24 09:25:13

1

每当你使用hbm.xml文件中,你将设置你的配置类是这样的:

Configuration cfg = new Configuration(); 
cfg.Configure(); 
// Add class mappings to configuration object 
cfg.AddAssembly(Assembly.GetCallingAssembly()); 
ISessionFactory sessionFactory = cfg.BuildSessionFactory(); 

每当你使用像CLASSE Nhibernate.Mapping.Attributes你将不得不使用: 例如,你有使用映射。属性产品分类

Configuration cfg = new Configuration(); 
cfg.Configure(); 
// Add class mappings attributes to configuration object 
cfg.AddInputStream(HbmSerializer.Default.Serialize(typeof(Model.Product); 
ISessionFactory sessionFactory = cfg.BuildSessionFactory(); 
2

我得到了问题。但突然发现映射文件没有嵌入。 转至.hbm.xml文件。点击属性。然后高级 - >选择“嵌入式资源”

相关问题