8

"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 used Hibernate in the past in Java projects.

Any help would be appreciated in pointing me where my error is.

I am using Visual Studio 2008 SP1 with Mysql 5.1.

Below is the code I am using. "

The full code and examples are posted here: https://forum.hibernate.org/viewtopic.php?f=25&t=997701

Cherian
  • 19,107
  • 12
  • 55
  • 69
Eduardo Xavier
  • 1,520
  • 21
  • 29

6 Answers6

17

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()
Andy Morris
  • 485
  • 3
  • 13
10

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 :)

Jeremy McGee
  • 24,842
  • 10
  • 63
  • 95
fcastellanos
  • 263
  • 2
  • 13
  • The poster on that forum states: "However this fix might cause unexpected problems.". I would still like to know what is causing this! – UpTheCreek Apr 27 '10 at 17:35
5

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>
Stuntbeaver
  • 690
  • 7
  • 8
3

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.
Knut Haugen
  • 1,962
  • 13
  • 16
2

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

cfg.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "none");
sth
  • 222,467
  • 53
  • 283
  • 367
0

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.

Chris Brandsma
  • 11,666
  • 5
  • 47
  • 58