开发者

error while compiling

error on line : config.AddAssembly("Hibernatetest");

Error Message : Could not compile the mapping document: Hibernatetest.Company.hbm.xml

Configuration config = new Configuration();
            ISessionFactory factory;
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
            config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2008Dialect");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver , "NHibernate.Driver.SqlClientDriver");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Data Source=(local);Initial Catalog=Chitty;Integrated Security=True");
            config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.Core.ProxyFactoryFactory ,NHibernate.ByteCode.Castle.Core");
            config.AddAssem开发者_StackOverflow中文版bly("Hibernatetest");

this is the company xml file

<hibernate-mapping xmlns="urn:nhibernate-mapping-3.0" namespace="Hibernatetest"
assembly="Hibernatetest">
  <class name="Company" table="Company">
    <id name="company_Id">
      <generator class="identity" />
    </id>
    <property name="company_name" type="string" />
    <property name="company_email" type="string"/>
    <property name="company_size" type="string"/>
  </class>
</hibernate-mapping>

please help


Hi I don't know why you put your namespace in the hbm file: Hibernatetest.Company.hbm.xml and also put the namespace in the class name:

This is how should look:

Company.hbm.xml

and

<hibernate-mapping xmlns="urn:nhibernate-mapping-3.0" namespace="Hibernatetest"
assembly="Hibernatetest">
  <class name="Company" table="Company">
    <id name="company_Id">
      <generator class="identity" />
    </id>
    <property name="company_name" type="string" />
    <property name="company_email" type="string"/>
    <property name="company_size" type="string"/>
  </class>
</hibernate-mapping>

Also you can get rid off the type but it's a good practice to put the column attribute in a property.


The class name is wrong, write the class name with the full namespace ( if you don't want to specify the namespace at the mapping level. The offending part is for sure the comma after the Company. And btw, if it does not solve, please add the class too in your question: it looks strange you have defined a c# class with properties named "company_name".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜