Hi all,
I'm doing a program that saves customer details to the database and I'm using NHibernate. I'm very new in it and I'm getting help from the net. I have a problem compiling the mapping file, I get the following error: "Could not compile the mapping document: Customer.hbm.xml"
I don't have an idea of what I did wrong. Please, if you know what I missed or did wrong, I'd really appreciate your help/advice. Thanks.
hibernate.cfg.xml <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate_Demo" /> </configSections> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory name="NH"> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> <property name="connection.driver_class">NHibernate.Driver.MsSql2005Dialect</property> <property name="connection.connection_string">Server=D9X3KQ3J\SQLEXPRESS; Initial Catalog=NHibernateTest; Integrated Security=SSPI;</property> <property name="connection.release_mode">on_close</property> <property name="show_sql">true</property>
<property name="use_outer_join">true</property> <!-- mapping files --> <!-- <mapping resource="User.hbm.xml" assembly="MysqlHibernet"/> --> <!-- <mapping resource="Products.hbm.xml" assembly="MysqlHibernet"/> --> <mapping assembly="NHibernate" /> </session-factory> </hibernate-configuration> </configuration>
Customer.hbm.xml
<?xml version="1.0" encoding="utf-8"?> <!--<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"> -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate" namespace="NHibernate_Demo" >
<class name="NHibernate_Demo.Customer, NHibernate_Demo" table="Customers" lazy="false"> <id name="CustomerID" type="String" length="5"> <generator class="assigned" /> </id> <property name="CompanyName" column="CompanyName" type="String" length="40"/> <property name="ContactName" column="ContactName" type="String" length="30"/> <property name="ContactTitle" column="ContactTitle" type="String" length="30"/> <property name="Phone" column="Phone" type="String" length="24"/> </class> </hibernate-mapping>
Here is my class:
using System; using System.Collections.Generic; using System.Text; using NHibernate; using NHibernate.Cfg;
namespace NHibernate_Demo {
class Program { static void Main(string[] args) {
// Loads the NHibernate Types to prepare for Serialization Configuration cfg = new Configuration(); cfg.Configure();
//cfg.AddAssembly(typeof(NHibernate_Demo.Customer).Assembly); //cfg.AddClass(typeof(Customer)); cfg.AddFile("Customer.hbm.xml");
//Opens a session to NHiberbate to allow us to work with objects ISessionFactory sessionsF = cfg.BuildSessionFactory();
//let ISessiionFactory open connection ISession sessionS = sessionsF.OpenSession();
ITransaction transaction = sessionS.BeginTransaction(); { Customer customer = (Customer) sessionS.Load(typeof(Customer), "ALFKI");
// Show the Contact Name of the Customer //MessageBox.Show(customer.ContactName);
sessionS.Close(); }
}
}
}
I get an error at this line:
cfg.AddFile("Customer.hbm.xml");
Thanks.
|