The most recent use of the NHibernate mapping type is the CLOB field when inserting data to find the number of bytes (one half-width character one byte, one full-width character two bytes) between 2000-4000 times wrong (ORA-01461: You can only insert a Long value assignment for a long column). After constantly looking for information and their own test the problem is finally resolved, below I will own experience to do a share.
Ready to
System Environment xp+.net2.0+oracle9i
Table structure (because it is a test, the table structure casually built a sheet) XX
Field name |
type |
CONFIG |
Clob |
1.
Using System;
Using System.Collections;
Using System.Collections.Generic;
Using UNI. Fs. Capability.DAL.Base;
Namespace UNI. Fs. Capability.DAL.Model
{
public partial class Gatherpoint:businessbase<string>
{
#region Declarations
Private System.String _config = null;
<summary>
Configuration
</summary>
Public virtual System.String ConFig
{
get {return _config;}
Set
{
Onconfigchanging ();
_config = value;
Onconfigchanged ();
}
}
partial void onconfigchanging ();
partial void onconfigchanged ();
}
}
Use NHibernate custom type, is not too will, fortunately on-line has the high man to provide the code, here wants the expert to thank. This allows us to set the correct oracletype by customizing the type. Add two classes to your project.
2.oracleclobfield.cs
Using System;
Using System.Collections.Generic;
Using System.Data;
Using System.Data.OracleClient;
Using System.Text;
Namespace UNI. Fs. Capability.DAL.type
{
public class Oracleclobfield:patchfororaclelobfield
{
public override void Nullsafeset (IDbCommand cmd, object value, int index)
{
If (cmd is OracleCommand)
{
CLob, Nclob type of field, when stored in Chinese, the oracledbtype of the parameter must be set to Oracledbtype.clob
Otherwise it will become garbled (Oracle 10g client environment)
OracleParameter param = cmd. Parameters[index] as OracleParameter;
if (param!= null)
{
Param. OracleType = oracletype.clob;//key right here.
Param. IsNullable = true;
}
}
NHibernate.NHibernateUtil.StringClob.NullSafeSet (cmd, value, index);
}
}
}
3.patchfororaclelobfield.cs
Using System;
Using System.Collections.Generic;
Using System.Data;
Using System.Text;
Using NHibernate;
Using Nhibernate.sqltypes;
Using Nhibernate.usertypes;
Namespace UNI. Fs. Capability.DAL.type
{
Public abstract class Patchfororaclelobfield:iusertype
{
Public Patchfororaclelobfield ()
{
}
public bool ismutable
{
get {true;}
}
public System.Type returnedtype
{
get {typeof (String);
}
public sqltype[] SqlTypes
{
get
{
return new sqltype[] {NHibernateUtil.String.SqlType};
}
}
public Object Deepcopy (object value)
{
return value;
}
public new bool Equals ( Object x, Object y)
{
return x = = y;
}
public int GetHashCode (object x)
{
return x.gethashcode ();
}
public Object Assemble ( Object cached, object owner
{
return deepcopy (cached);
}
public object disassemble (object value)
{
return deepcopy (value);
}
public Object Nullsafeget (IDataReader RS, string[] names, object owner)
{
Return NHibernate.NHibernateUtil.StringClob.NullSafeGet (RS, names[0]);
}
public abstract void Nullsafeset (IDbCommand cmd, object value, int index);
public Object Replace (object original, object target, object owner)
{
return original;
}
}
}
4.<property name= "ConFig" type= "UNI. Fs. Capability.dal.type.oracleclobfield,uni. Fs. Capability.dal "column=" CONFIG "/>
Transferred from http://www.cnblogs.com/luluping/archive/2010/02/03/1662935.html