zoukankan      html  css  js  c++  java
  • NHibernate 错误:Could not compile the mapping document 解决方法

    初次玩NHibernate,就遇到一个拦路虎,报错如下:Could not compile the mapping document: NhibernateForm.NhibernateForm.Student.hbm.xml

    不可否认是*.hbm.xml这个文件配置有误,但是查找了半天都没找到原因。

    最后在http://blog.csdn.net/tyh800220/article/details/1733133 找到解决方案,感谢博主。

    解决方案:

     <class
            name="NhibernateForm.Student,NhibernateForm"
            discriminator-value="0"
        >

    重点在name这个属性,加上程序集即可。

    但是查阅官方的API文档,也是如此:

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="QuickStart" assembly="QuickStart">
    <class name="Cat" table="Cat">
    <!-- A 32 hex character is our surrogate key. It's automatically
    generated by NHibernate with the UUID pattern. -->
    <id name="Id">
    <column name="CatId" sql-type="char(32)" not-null="true"/>
    <generator class="uuid.hex" />
    </id>
    <!-- A cat has to have a name, but it shouldn' be too long. -->
    <property name="Name">
    <column name="Name" length="16" not-null="true" />
    </property>
    <property name="Sex" />
    <property name="Weight" />
    </class>
    </hibernate-mapping>

    然而,然而,让我感觉奇怪的是,官方给出的Demo中却又把程序集加上了。如下:

    <?xml version="1.0" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
    	<class 
    		name="NHibernate.DomainModel.A, NHibernate.DomainModel" 
    		discriminator-value="0"
    	>
    		<id 
    			name="Id" column="identifier_column"
    			unsaved-value="0"
    		>
    			<generator class="increment" />
    			<!-- unsaved-value used to be null and generator was increment in h2.0.3 -->
    		</id>
    ...	
    

    这让我严重怀疑官方的API中的示例是否经过了测试。

    我用的NHibernate版本是3.3.1,感觉NH各个版本的配置有蛮多差别,而这些细微的差别会导致很多问题,这让那些后来学习者增添了很多烦恼。感觉学习的主动性要把握在自己的手里仅有两条路可走:1、阅读官方E文文档;2、阅读源码。这也是最好的两种学习方法。

     修正:

    经过再次仔细阅读官方API文档说明,看到如下这句话,让我顿悟:

    If you are not using assembly and namespace attributes, you have to specify fully-qualified class names, including
    the name of the assembly that classes are declared in.

    也就是说:

    如果Map映射文件中的hibernate-mapping节点属性中没有设置assemblynamespace ,那么class节点中就必须使用限定名,类名和程序集都必须定义。而我就是在hibernate-mapping节点没有设置assemblynamespace ,class节点也没有使用全名称的情况下出的错误。

  • 相关阅读:
    什么是方法以及evall()和isnan()和number()string()的使用
    js的本质/数据类型
    if条件的种类
    js中期知识点总结11月7日
    js中期知识点总结11月6日
    js中期知识点总结11月5日
    js中期知识点总结11月2日
    js中期总结11月1日
    js中期知识点总结10月31日
    html前期js知识点10月25日
  • 原文地址:https://www.cnblogs.com/hangwq/p/2824060.html
Copyright © 2011-2022 走看看