styles_p 0 Newbie Poster

Hello I'm a newbie of nhibernate
And i would like to use the NHibernate Mapping

here is my mapping file

<?xml version="1.0" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="HibernateCollaborator.Core" namespace="HibernateCollaborator.Core" default-access="property" default-cascade="none" default-lazy="false" auto-import="true" >
  <class name="User" table="Users" lazy="false">
    <id name="ID" column="ID" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="ForeName" type="string" length="30" not-null="true">
      <column name="ForeName" sql-type="varchar" length="30" not-null="true"/>
    </property>
    <property name="SureName" type="string"  not-null="true">
      <column name="SureName" sql-type="varchar" length="30" not-null="true"/>
    </property>
    <property name="Username" type="string"  not-null="true">
      <column name="Username" sql-type="varchar" length="30" not-null="true"/>
    </property>
    <property name="Password" type="string"  not-null="true">
      <column name="Password" sql-type="varchar" length="30" not-null="true"/>
    </property>
    <property name="Email" type="string"  not-null="true">
      <column name="Email" sql-type="varchar" length="30" not-null="true"/>
    </property>
   </class>
</hibernate-mapping>

I think there're everything OK...

and in the class I have written something like this...

Public Class UserData{
 public void CreateEmployeeAndSaveToDatabase() {
            User u = new User();
            u.ForeName = "John";
            u.SureName = "Smith";
            u.Username = "John1894";
            u.Password = "sasa";
            u.Email = "Ererewf";
            using (ISession session = factory.OpenSession()) {
        using (ITransaction transaction = session.BeginTransaction()) {
                    session.Save(u);
                    transaction.Commit();
                }
            }
        }
        ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure().AddXmlFile("User.hbm.xml").BuildSessionFactory();  
}

here rises exception:

MappingException was unhandled by user code ["Could not configure datastore from file User.hbm.xml" ]

would you advice my anything??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.