我正在使用NHibernate 3.3和ODP.NET来持久化到Oracle11g数据库,这是相对于配置的部分:
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
我将byte []属性映射到BLOB字段并设置块以执行插入存储过程,如下所示:
<class name="Digital" table="DIGITALS">
<id name="Id" column="COD_DIGITAL">
<generator class="increment" />
</id>
<property name="File" column="FILE" />
<sql-insert>begin PKG_DIGITALS.insert_sp(?,?); end;</sql-insert>
数字实体在大小&lt; = 32k文件时保持正常;但是我收到这个错误[ORA-01460:请求未实现或不合理的转换],大小> 32k文件。
这是司机限制吗? 我怎么能解决这个问题?
答案 0 :(得分:0)
我遇到了同样的问题(NHibernate 3.3.1.4000,Oracle 11g)。 NHibernates OracleDataClientDriver设置dbParam.DbType = DbType.Binary。这导致32K限制。当设置dbParam.OracleDbType = OracleDbType.Blob时,限制消失了。 为了存档,我创建了自己的Oracle驱动程序:
public class OracleOdpClientDriver : OracleDataClientDriver
{
protected override void InitializeParameter(System.Data.IDbDataParameter dbParam, string name, NHibernate.SqlTypes.SqlType sqlType)
{
base.InitializeParameter(dbParam, name, sqlType);
var oraParam = dbParam as OracleParameter;
if (oraParam != null)
{
if (sqlType.DbType == System.Data.DbType.Binary)
// Use Oracle Blob instead of Binary to prevent a 32K limit.
oraParam.OracleDbType = OracleDbType.Blob;
else if (sqlType.DbType == System.Data.DbType.String && sqlType.LengthDefined && sqlType.Length >= 32768)
// StringClob params must not be mapped to Varchar2 because that has a 32K limit.
oraParam.OracleDbType = OracleDbType.Clob;
}
}
最后,驱动程序需要在config中注册:
<property name="connection.driver_class">MyDataAccess.OracleOdpClientDriver, MyDataAccess</property>