The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property'

StackOverflow https://stackoverflow.com/questions/9775934

  •  25-05-2021
  •  | 
  •  

Question

The hbm file is:

<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>

The 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;
        }
    }
    }
}

And this is the IEmployee.cs:

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

Now I am getting the exception:

The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'.

I am using Spring.Net with NHibernate. The invocation of the hbm file is:

<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>

The project structure is:

enter image description here

Any help will be very helpful.

Thanks.

Was it helpful?

Solution

You are missing the id element, which comes before all properties in the schema.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top