2012-01-05 10 views
4

私はdbとしてOracleを使用し、マッピングには流暢なNhibernateを使用しています。以下はOracleでN-Hibernateの長い文字列にエラーが発生する

財産EventScriptの長さは、私がEventScriptの列タイプCLOB行われたデータベースでは0〜4000 にすることができ

public class UserFieldEvent 
    { 
     public virtual int Id { get; set; } 
     public virtual UserFieldBase UserField { get; set; } 
     public virtual EventType EventType { get; set; } 
     public virtual string EventScript { get; set; } 
    } 

私のオブジェクトクラスです。

以下

が私のマッピングクラスである:

public UserFieldEventMap() 
     { 
      Table("TBLDS_USERFIELDEVENT"); 
      Id(x => x.Id).GeneratedBy.Sequence("SEQDS_USERFIELDEVENT"); 
      Map(x => x.EventType).CustomType<EventType>(); 
      Map(x => x.EventScript).CustomSqlType("CLOB"); 
      References(x => x.UserField).Column("USERFIELDBASEID"); 
     } 

今EventScriptの長さが2000以上である時はいつでも私は、エラー「ORA-01461を:LONG列にのみ挿入用のLONG値をバインドすることができます。」取得しますオブジェクトをデータベースに保存します。誰でもこれを助けることができます。

答えて

5

これは、.NETで提供されている既知の問題です。System.Data.OracleClient.OracleConnectionドライバ。この修正は、Oracle提供のODP.netクライアントOracle.DataAccess.Client.OracleConnectionhttp://nuget.org/packages/odp.net.x86/を参照)を使用するか、次の回避策(http://thebasilet.blogspot.be/2009/07/nhibernate-oracle-clobs.htmlから参照)を使用することです。

public class CustomOracleDriver : OracleClientDriver 
{ 
    protected override void InitializeParameter(System.Data.IDbDataParameter dbParam, string name, SqlType sqlType) 
    { 
     base.InitializeParameter(dbParam, name, sqlType); 


     // System.Data.OracleClient.dll driver generates an ORA-01461 exception because 
     // the driver mistakenly infers the column type of the string being saved, and 
     // tries forcing the server to update a LONG value into a CLOB/NCLOB column type. 
     // The reason for the incorrect behavior is even more obscure and only happens 
     // when all the following conditions are met. 
     // 1.) IDbDataParameter.Value = (string whose length: 4000 > length > 2000) 
     // 2.) IDbDataParameter.DbType = DbType.String 
     // 3.) DB Column is of type NCLOB/CLOB 

     // The above is the default behavior for NHibernate.OracleClientDriver 
     // So we use the built-in StringClobSqlType to tell the driver to use the NClob Oracle type 
     // This will work for both NCLOB/CLOBs without issues. 
     // Mapping file must be updated to use StringClob as the property type 
     // See: http://thebasilet.blogspot.be/2009/07/nhibernate-oracle-clobs.html 
     if ((sqlType is StringClobSqlType)) 
     { 
      ((OracleParameter)dbParam).OracleType = OracleType.NClob; 
     } 
    } 
} 

あなたはStringClobカスタム型を使用するには、このドライバを使用するだけでなく、あなたのCLOBマッピングのいずれかを更新するために、あなたのSessionFactoryを更新する必要があり

Map(x => x.EventType).CustomSqlType("Clob").CustomType("StringClob"); 
関連する問題