2012-03-19 61 views
5

HBM的文件是:元素命名空間「類的」甕:NHibernate的映射 - 2.2具有無效的子元素 '財產'

<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'具有 命名空間 'urn:nhibernate-mapping-2.2'中的無效子元素'property'。預期可能的元素列表: 'meta,subselect,cache,synchronize,comment,tuplizer,id, composite-id'in namespace'urn:nhibernate-mapping-2.2'。

我使用Spring.Net與NHibernate。 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

任何幫助將是非常有益的。

謝謝。

回答

11

您缺少id元素,它位於架構中的所有屬性之前。

+0

果然,我的班級中缺少ID元素和屬性。泰! – SushiGuy 2015-09-30 21:18:10

相關問題