NHibernate + MySql = Weird Erro(列“ReservedWord”不属于表 ReservedWords。)

本文记录了使用NHibernate 2.2与MySQL时遇到的配置问题及解决方法。作者在VS2008环境下配置NHibernate时,因为表名与MySQL关键字冲突导致异常。最终通过设置hbm2ddl.keywords为none解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    VS2008, Mvc 1.0, NHibernate 2.2, MySql XX, 按照 NH 官方示例配置 Web.config

<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory name="NHibernate.Test">
        <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
        <property name="connection.connection_string">
            Database=test;Data Source=someip;User Id=blah;Password=blah
        </property>
        <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    </session-factory>
</hibernate-configuration>
 

    然后运行出现黄页:

“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------

列“ReservedWord”不属于表 ReservedWords。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.ArgumentException: 列“ReservedWord”不属于表 ReservedWords。

源错误: 


行 12: 
行 13:         static NHibernateHelper() {
行 14:             sessionFactory = new Configuration().Configure().BuildSessionFactory();
行 15:         }
行 16: 
 

源文件: E:\Documents\SVN\MIS\project\OpenService\FilesII\FilesII.DAL\NHibernateHelper.cs    行: 14 

堆栈跟踪: 


[ArgumentException: 列“ReservedWord”不属于表 ReservedWords。]
   System.Data.DataRow.GetDataColumn(String columnName) +1773557
   System.Data.DataRow.get_Item(String columnName) +13
   NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetReservedWords() +237
  ...

    寡人我辗转 Google、百度 之中文资料,终不得解;无奈,偶见一外文网页,点入、跟踪,解决:

http://www.google.cn/search?hl=zh-CN&q=nhibernate+mysql+ReservedWord&btnG=Google+搜索

https://forum.hibernate.org/viewtopic.php?f=25&t=997701

Barlog

Post subject: Re: Column 'ReservedWord' does not belong to table ReservedWords

Posted: Wed Jul 22, 2009 9:43 am 

Newbie

Joined: Wed Jul 22, 2009 9:24 am
Posts: 1

Greetings.
Just add following line to configuration file to <session-factory> section.
<property name="hbm2ddl.keywords">none</property>
However this fix might cause unexpected problems. :|
Best regards.

_________________
Infinite diversity in infinite combination

   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值