0

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

Edited by mike_2000_17: Fixed formatting

1
Contributor
2
Replies
3
Views
7 Years
Discussion Span
Last Post by styles_p
0

ok I solved it but rised another problem in session.Save(u);
Unknown entity class: HibernateCollaborator.Core.User but there is this class, I haven't idea why rised this error :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.