Thursday, October 1, 2009

Problem inserting large characters strings in Oracle using NHibernate

I am currently on a very large eCommerce project at the State of VA and we came across a very interesting error from Oracle using NHibernate 1.2. For about 3 days, my team have been banging our heads against the wall to find out how to insert large character string of over 4000 characters in Oracle using NHibernate. We tried changing the column type in the database, adding in conventions to Fluent, changing proptery mappings, and we were even disperate enough to add multiple columns in to chuck the characters out in the database table.

Then I remember running across another blog post of a different issue where I saw a posting talking about Microsoft's version of  Oracle's data client does not handle large characters type to well where Oracle would push back a error message like this "ORA-01461: can bind a LONG value only for insert into a LONG column". Even though it was a clob column, got to love Oracle's clear and to the point error messages.

After a few minutes of changing around the web.config and NHibernate.config files, the insert worked! Below I will describe how to fix the problem.

Update NHibernate.config file
We were using the NHibernate.Driver.OracleClientDriver which default to Microsoft's Oracle provider (System.Data.OracleClient). The first chnage is to change the driver_class property to NHibernate.Driver.OracleDataClientDriver shown in figure 1.

Figure 1:
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>

Add Reference to Oracle.DataAccess
Next, we have to add in the reference to Oracle.DataAccess dll to our website. This will allow NHibernate to find the dll to match the dialect. You can find this assembly in the oracle folder under ODP.NET.

Update Web.Config in your website
Now, we have to update our assemblybindings to accept the change for the addtion of Oracle.DataAccess dll. Below is the config change that needs to happen in your web.config.

figure 2:
<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>

Happy Coding!

1 comment: