I just setup NHibernate for the first time. My platform and config settings as follows:
I created a test MVC app with a test project. Then, to test for NHibernate connection, I use the following test fixture:
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);
new SchemaExport(cfg).Execute(false, true, false);
}
}
The Nhibernate config file:
<?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="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
<property name="connection.connection_string">
User ID=TEST;Password=******;Data Source=//RAND
</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>
On test, I get the following exception stack trace:
NHibernate.HibernateException was unhandled by user code
Message=Could not create the driver from NHibernate.Driver.OracleDataClientDriver.
Source=NHibernate
StackTrace:
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings) in d:\CSharp\NH\nhibernate\src\NHibernate\Connection\ConnectionProvider.cs:line 113
at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings) in d:\CSharp\NH\nhibernate\src\NHibernate\Connection\ConnectionProvider.cs:line 64
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings) in d:\CSharp\NH\nhibernate\src\NHibernate\Connection\ConnectionProviderFactory.cs:line 50
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1 scriptAction, Boolean export, Boolean justDrop) in d:\CSharp\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaExport.cs:line 333
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean export, Boolean justDrop) in d:\CSharp\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaExport.cs:line 290
at IBCService.Tests.GenerateSchema_Fixture.Can_generate_schema() in D:\APPS\VS2010\IBanking\CustomerService\IBCService.Tests\GenerateSchema_Fixture.cs:line 21
InnerException: System.Reflection.TargetInvocationException
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type) in d:\CSharp\NH\nhibernate\src\NHibernate\Bytecode\ActivatorObjectsFactory.cs:line 9
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings) in d:\CSharp\NH\nhibernate\src\NHibernate\Connection\ConnectionProvider.cs:line 107
InnerException: System.NullReferenceException
Message=Object reference not set to an instance of an object.
Source=NHibernate
StackTrace:
at NHibernate.Driver.OracleDataClientDriver..ctor() in d:\CSharp\NH\nhibernate\src\NHibernate\Driver\OracleDataClientDriver.cs:line 42
InnerException:
If I change NHibernate.Driver.OracleDataClientDriver to NHibernate.Driver.OracleClientDriver (MS provider for Oracle), the test succeed. Can someone tell me what I'm doing wrong?
Hi I think the error happens, because Nhibernate is not loading the driver from the GAC with Assembly.LoadWithPartialName(), but with Assembly.Load(). Try to place Oracle.DataAccess.dll in the bin directory or use qualifyAssembly section into your app.config or web.config. Example:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Oracle.DataAccess"
fullName="Oracle.DataAccess, Version=2.102.2.20, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</assemblyBinding>
</runtime>
@PerlDev: I think that you have a "ODP.NET 32 bit binary" installed and you are compiling your app with platform "AnyCPU". If so, try to change to x86 (this is what I did, and worked).
If you want to compile as x64 I think you must install the "ODP.NET 64 bit binary" (I didn´t do it yet).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With