MySQL & NHibernate. How fix the error: Column 'ReservedWord' does not belong to table ReservedWords?

后端 未结 6 927
夕颜
夕颜 2021-02-15 11:52

\"I am getting a weird error when using NHibernate. And I don\'t know what is causing this error. I am new to the whole Visual Studio and NHibernate, but not to Hibernate. I use

相关标签:
6条回答
  • 2021-02-15 12:13

    This resolves the same error when using ActiveRecord for NHibernate. The relevant bit is key="hbm2ddl.keywords" value="none" and this goes in your web.config.

    <activerecord isWeb="true">
        <config>
            <add key="connection.driver_class" value="NHibernate.Driver.MySqlDataDriver"/>
            <add key="dialect" value="NHibernate.Dialect.MySQLDialect"/>
            <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
            <add key="connection.connection_string_name" value="BrochureDb"/>
            <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"/>
            <add key="hbm2ddl.keywords" value="none" />
        </config>
    </activerecord>
    
    0 讨论(0)
  • 2021-02-15 12:19

    I just hit this issue as well. I ended up doing this:

    http://orbitalcoder.wordpress.com/2009/08/18/proposed-solution-for-the-nhibernate-exception-column-reserved-word-does-not-belong-to-table-reservedwords/

    which is a code change to NHibernate, but worked for me.

    0 讨论(0)
  • 2021-02-15 12:20

    I got the same error but I'm using MySQL+NHibernate (2.1.0GA) + Mono (2.4) under Ubuntu and this link helped me, hope it works for you.

    The key is to use this in session-factory

    <property name="hbm2ddl.keywords">none</property>
    

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

    that was it :)

    0 讨论(0)
  • 2021-02-15 12:34

    If doing it programmatically, you should do it as such:

    cfg.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "none");
    
    0 讨论(0)
  • 2021-02-15 12:34

    My first guess is that NHibernate identifies a column and/or table name as a reserved word. Your class named "hibernate" could be a likely culprit but without more information about your error it's a bit hard to track down. Some suggestions:

    1. try renaming the table and columns both in the database and config and give it a test
    2. Download log4net (http://logging.apache.org/log4net/download.html) and check out https://www.hibernate.org/364.html to configure it for nhibernate. Set it to debug and dig into the log file and see the full information on the stacktrace/error you get.
    0 讨论(0)
  • 2021-02-15 12:36

    FYI for any NHibernate/Fluent NHibernate newbies like myself, FCastellanos' solution worked for me as well (I got the error on Windows as well), and the Fluent NHibernate way to add that configuration is:

    Fluently.Configure()
        ...
        .ExposeConfiguration(c => c.Properties.Add("hbm2ddl.keywords", "none"))
        ...
        .BuildSessionFactory()
    
    0 讨论(0)
提交回复
热议问题