views:

1344

answers:

2

I need to get NHibernate 2.1 to talk to an oracle database. I am being required to use the Orace 10g client. I get the following error when trying to build my session factory:

Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'.

I don't recall getting this error with NHibernate 2.01. I am trying to get the server admins to install the 11g client, but it looks like that is a loosing battle.

Here are the important bits from my web.config:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <qualifyAssembly partialName="Oracle.DataAccess" fullName="Oracle.DataAccess, Version=10.2.0.100, Culture=Neutral, PublicKeyToken=89b483f429c47342"/>    
  </assemblyBinding>
</runtime>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
 <session-factory>
   <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
   <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
   <property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
   <property name="connection.connection_string_name">Demo</property>
   <property name="show_sql">false</property>
   <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
  </session-factory>
</hibernate-configuration>

Full stack trace

at NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare()
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at ConsoleApplication6.Program.Main(String[] args) in C:\\Dev\\Temp\\ConsoleApplication6\\Program.cs:line 26
+6  A: 

I asked this same question in the NHUsers group, and got an acceptable answer. Add the following to the hibernate configuration:

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

See http://fabiomaulo.blogspot.com/2009/06/auto-quote-tablecolumn-names.html

JohnRudolfLewis
thanks that saved my day
Scott Cowan
+1  A: 

I am having the same problem. I need to use the Schema Export function as our tests relays on it. I was hoping to use tha latest version of NH so we could have a look at the new linq features.

Did you find any other work around besides rolling back to version 2.0.1?

Ealbert
See the above configuration entry and Fabio's blog entry.
JohnRudolfLewis