首页 新闻 会员 周边 捐助

winform程序使用nhibernate的奇怪问题。加载hbm.xml文件时总是提示Could n

0
悬赏园豆:20 [已关闭问题]

这个问题困惑我挺长时间了,每次加载hbm.xml文件的时候就报这个错误。 
Could not find the dialect in the configuration 
下边是我的代码。 
1 app.config 
<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
  <configSections> 
  <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.1.4000,Culture=neutral, PublicKeyToken=b77a5c561934e089,Custom=null" /> 
  </configSections> 
  <nhibernate xmlns="urn:nhibernate-configuration-2.2"> 
  <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /> 
  <add key="hibernate.prepare_sql" value="false" /> 
  <add key="hibernate.cache.provider_class" value="NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache" /> 
  <add key="relativeExpiration" value="30" /> 

  <add key="hibernate.dialect" value="NHibernate.Dialect.Oracle9Dialect"/> 
  <add key="hibernate.connection.driver_class" value="NHibernate.Driver.OracleDataClientDriver" /> 
  <add key="hibernate.connection.connection_string" value="Data Source=DATABASE;Persist Security Info=True;User ID=cyd;Password=cyd;Unicode=True;" /> 
  <add key="hibernate.hbm" value="CorpTemplate.Business" /> 
  <property name="dialect">NHibernate.Dialect.Oracle9Dialect </property> 
  </nhibernate> 
</configuration> 

2.userinfor 类 

namespace NHibernateLearning 

  public class UserInfor 
  { 
  private string _userID; 
  public string UserID 
  { 
  get { return _userID; } 
  set { _userID = value; } 
  } 

  private string _userName; 
  public string UserName 
  { 
  get { return _userName; } 
  set { _userName = value; } 
  } 
  } 


3 UserInfor.hbm.xml 

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="NHibernateLearning" namespace="NHibernateLearning"> 
  <class name="NHibernateLearning.UserInfor, UserInfor" table="userinfor"> 
  <id name="UserID" column="userid" type="string"> 
  <generator class="native" /> 
  </id> 
  <property name="userName" column= "userName" type="string" length="20"/> 
  </class> 
</hibernate-mapping> 

4.form的构造函数 

  public Form1() 
  { 
  InitializeComponent(); 

  mCfg.AddXmlFile("D:\\C#\\NHibernateLearning\\NHibernateLearning\\UserInfor.hbm.xml"); 

  sessionFactory = mCfg.BuildSessionFactory(); 
  } 
每次执行到mCfg.AddXmlFile("D:\\C#\\NHibernateLearning\\NHibernateLearning\\UserInfor.hbm.xml");就会报刚才那个错误。 
Could not compile the mapping document: D:\\C#\\NHibernateLearning\\NHibernateLearning\\UserInfor.hbm.xml"} 
我已经把UserInfor.hbm.xml设置成Embedded Resource(嵌入式资源)了。 
有没有高手给解答一下啊,刚开始学nhibernate。第一步就卡住了。愁死了。

Eddie Chen的主页 Eddie Chen | 初学一级 | 园豆:150
提问于:2009-06-09 16:30
< >
分享
其他回答(1)
0

  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <!-- an ISessionFactory instance -->
    <session-factory>
      <!-- properties -->
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="connection.connection_string_name">Savory</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="max_fetch_depth">1</property>
      <property name="show_sql">true</property>
    </session-factory>
  </hibernate-configuration>

我的配置节点是这样的,好像是用<property>不是用<add>……

Gray Zhang | 园豆:17610 (专家六级) | 2009-06-09 21:38
0

你把UserInfor.hbm.xml设置成Embedded Resource了,本地就没这个文件了,被编译到dll中了

所以:每次执行到mCfg.AddXmlFile("D:\\C#\\NHibernateLearning\\NHibernateLearning\\UserInfor.hbm.xml");就会报刚才那个错误。 
Could not compile the mapping document: D:\\C#\\NHibernateLearning\\NHibernateLearning\\UserInfor.hbm.xml"}

不要设置为Embedded Resource 或者读取签入的资源,例如:

Code

winzheng | 园豆:8797 (大侠五级) | 2009-06-10 10:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册