我正在尋找從XDocument屬性類型映射到Oracle XMLType的最佳方法?我正在映射到遺留數據庫,並且無法控制架構。它是Oracle 9i。Fluent NHibernate將XDocument屬性映射到Oracle XMLType
我已經讀過nHibernate的第3版提供了這種類型的映射的出箱功能。我使用3.1版本,用流利的映射和我用一個創建默認的地圖時收到以下錯誤:
System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. at Oracle.DataAccess.Client.OracleParameter.set_DbType(DbType value) at NHibernate.Driver.DriverBase.SetCommandParameters(IDbCommand cmd, SqlType[] sqlTypes) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Driver\DriverBase.cs: line 180 at NHibernate.Driver.DriverBase.GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Driver\DriverBase.cs: line 136 at NHibernate.AdoNet.AbstractBatcher.Generate(CommandType type, SqlString sqlString, SqlType[] parameterTypes) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs: line 78 at NHibernate.AdoNet.AbstractBatcher.PrepareBatchCommand(CommandType type, SqlString sql, SqlType[] parameterTypes) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs: line 146 at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 2616 at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs: line 3050 at NHibernate.Action.EntityInsertAction.Execute() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Action\EntityInsertAction.cs: line 59 at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs: line 136 at NHibernate.Engine.ActionQueue.ExecuteActions(IList list) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs: line 125 at NHibernate.Engine.ActionQueue.ExecuteActions() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs: line 170 at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs: line 241 at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultFlushEventListener.cs: line 20 at NHibernate.Impl.SessionImpl.Flush() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs: line 1470
我得到了這一輪我寫這一個XDocument和一個字符串之間的轉換我自己的用戶類型:
public SqlType[] SqlTypes
{
get { return (new SqlType[] { new StringClobSqlType() }); }
}
public Type ReturnedType
{
get { return (typeof(XDocument)); }
}
public object NullSafeGet(IDataReader rs, string[] names, object owner)
{
XDocument xDoc = null;
int columnIndex = rs.GetOrdinal(names[0]);
if (!rs.IsDBNull(columnIndex))
{
xDoc = XDocument.Parse((rs[columnIndex].ToString()));
}
return (xDoc);
}
public void NullSafeSet(IDbCommand cmd, object value, int index)
{
IDbDataParameter parameter = (IDbDataParameter)cmd.Parameters[index];
if (value == null)
{
parameter.Value = DBNull.Value;
}
else
{
XDocument xDoc = (XDocument)value;
parameter.Value = xDoc.ConvertToString();
}
}
這工作正常,直到字符串的長度大於4000個字符。現在,我得到的錯誤:
NHibernate.Exceptions.GenericADOException : could not insert: [XmlBlob#95586][SQL: INSERT INTO XMLBLOB (CAT_CODE, BLB_BLOB, BLB_ID) VALUES (?, ?, ?)] ----> Oracle.DataAccess.Client.OracleException : ORA-01461: can bind a LONG value only for insert into a LONG column