views:

2182

answers:

6

"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

+1  A: 

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
+5  A: 

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

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

that was it :)

FCastellanos
The poster on that forum states: "However this fix might cause unexpected problems.". I would still like to know what is causing this!
UpTheCreek
+11  A: 

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
+1 Worked here using SQLAnywhere10.
Zote
A: 

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

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

cfg.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "none");
+3  A: 

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