Reputation: 38638
I have a table in Oracle database with a column of Long
type. In this column, we store a long text and we cannot change the type to CLob
because there are other systems that use it as Long
type. I am writting a new application to read this column and execute some tasks using NHibernate
and Fluent NHibernate
to map.
The mapping is ok, everything works except this column. When I read a entity from this table, the long
column comes a string empty like ""
.
I have tried these:
Map(x => x.Query).Column("PNL_QUERY");
and
Map(x => x.Query).Column("PNL_QUERY").CustomType("StringClob");
and
Map(x => x.Query).Column("PNL_QUERY").CustomType("StringClob")
.CustomSqlType("Long");
and
Map(x => x.Query).Column("PNL_QUERY").CustomType("Long");
and nothing works. All of them return ""
in the Query field, when I load some entity from database.
How could I map this type of column in Oracle?
Thank you.
Upvotes: 2
Views: 1565
Reputation: 38638
I found a solution:
To get the LONG
columns working, in the ado.net oracle provider we have to set the OracleCommand.InitialLONGFetchSize
property to -1
. So we have to override the Oracle Driver from OracleDataClientDriver
class. Something like this:
using NHibernate.Driver; using Oracle.DataAccess.Client;
namespace MyProject
{
public class OracleDriverExtended : OracleDataClientDriver
{
public override void AdjustCommand(System.Data.IDbCommand command)
{
OracleCommand cmd = command as OracleCommand;
if (cmd != null)
cmd.InitialLONGFetchSize = -1;
}
}
}
And in the hibernate.cfg.xml
set this custom driver to the connection.driver_class
property:
<property name="connection.driver_class">
MyProject.Data.OracleDriverExtended,
MyProject
</property>
Now, NHibernate can read the LONG
types from Oracle.
I found the solution here http://sonyarouje.com/2012/11/07/nhibernate-and-oracle-long-varchar-field/
Upvotes: 3