命名空间'urn:nhibernate-mapping-2.2'中的元素'class'具有无效的子元素'property'

时间:2012-03-19 18:41:29

标签: c# nhibernate hbm

hbm文件是:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name="EMSApplication.Domain.Employee, EMSApplication.Domain" table="ems_Employees" proxy="EMSApplication.Domain.IEmployee, EMSApplication.Domain">
    <property name="Username">
        <column name="Username" length="40" sql-type="nvarchar" not-null="true" index="Username"/>
    </property>
    <property name="Firstname">
        <column name="Firstname" length="40" sql-type="nvarchar" not-null="true" index="Firstname"/>
    </property>
    </class>
</hibernate-mapping>

Employee.cs:

namespace EMSApplication.Domain {
    public class Employee : IEmployee {
    private string username;
    private string firstname;

    public virtual string Firstname {
        get {
        return firstname;
        }
        set {
        firstname = value;
        }
    }

    public virtual string Username {
        get {
        return username;
        }
        set {
        username = value;
        }
    }
    }
}

这是IEmployee.cs:

namespace EMSApplication.Domain {
    interface IEmployee {
    string Firstname { get; set; }
    string Username { get; set; }
    }
}

现在我得到了例外:

  

命名空间'urn:nhibernate-mapping-2.2'中的元素'class'具有   命名空间中的无效子元素'property'   '瓮:NHibernate的映射-2.2'。预期的可能元素列表:   'meta,subselect,cache,synchronize,comment,tuplizer,id,   命名空间'urn:nhibernate-mapping-2.2'中的composite-id'。

我正在使用带有NHibernate的Spring.Net。调用hbm文件是:

<object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate32">
    <property name="DbProvider" ref="DbProvider"/>
    <property name="MappingResources">
    <list>
        <value>assembly://EMSApplication/EMSApplication.Domain/EMSApplication.hbm.xml</value>
    </list>
    </property>
    <property name="HibernateProperties">
    <dictionary>
        <entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
        <entry key="dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
        <entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
        <entry key="proxyfactory.factory_class" value="NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate"/>
        <entry key="show_sql" value="true"/>
        <entry key="hbm2ddl.auto" value="update"/>
        <entry key="cache.use_query_cache" value="true"/>
    </dictionary>
    </property>

    <property name="ExposeTransactionAwareSessionFactory" value="true" />
</object>

项目结构是:

enter image description here

任何帮助都会非常有帮助。

感谢。

1 个答案:

答案 0 :(得分:12)

您缺少id元素,该元素位于架构中的所有属性之前。