Connection Error using NHibernate 3.0 with Oracle

Posted by Olu Lawrence on Stack Overflow See other posts from Stack Overflow or by Olu Lawrence
Published on 2010-12-31T16:55:03Z Indexed on 2011/01/01 1:54 UTC
Read the original article Hit count: 583

Filed under:

I'm new to NHibernate. My first attempt is to configure and establish connection to Oracle 11.1g using ODP. For this test, I use a test fixture, but I get the following error:

Inner exception: "Object reference not set to an instance of an object." Outer exception: Could not create the driver from NHibernate.Driver.OracleDataClientDriver.

The test script is shown below:

using IBCService.Models;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NUnit.Framework;
namespace IBCService.Tests
{
    [TestFixture]
    public class GenerateSchema_Fixture
    {
        [Test]
        public void Can_generate_schema()
        {
            var cfg = new Configuration();
            cfg.Configure();
            cfg.AddAssembly(typeof(Product).Assembly);
            var fac = new SchemaExport(cfg);
            fac.Execute(false, true, false);

        }
    }
}

The exception occurs at the last line: fac.Execute(false, true, false);

The NHibernate config is shown:

<?xml version="1.0" encoding="utf-8"?>
<!-- This config use Oracle Data Provider (ODP.NET) -->
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory name="IBCService.Tests">
    <property name="connection.driver_class">
        NHibernate.Driver.OracleDataClientDriver
    </property>
    <property name="connection.connection_string">
      User ID=TEST;Password=test;Data Source=//RAND23:1521/RAND.PREVALENT.COM
    </property>
    <property name="connection.provider">
        NHibernate.Connection.DriverConnectionProvider
    </property>
    <property name="show_sql">false</property>
    <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
    <property name="query.substitutions">
        true 1, false 0, yes 'Y', no 'N'
    </property>
    <property name="proxyfactory.factory_class">
        NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
    </property>
  </session-factory>
</hibernate-configuration>

Now, if I change the NHibernate.Driver.OracleDataClientDriver to NHibernate.Driver.OracleClientDriver (Microsoft provider for Oracle), the test succeed. Once switched back to Oracle provider, whichever version, the test fails with the error stated earlier.

I've spent 3 days already trying to figure out what is not in order without success. I hope someone out there could provide useful info on what I am doing wrong.

© Stack Overflow or respective owner

Related posts about nhibernate