У меня есть хранимая процедура, которая, за исключением типа User, используется в качестве параметра. При вызове ее из Nhibernate она выдает следующее исключение.
Звонок из Nhibernate
<code>
EmployeeType emp = new EmployeeType(243214,"Anupam");<br>
IQuery final = eventhistorysession.CreateSQLQuery("call testCustom (:pLocation)");
final.SetParameter("pLocation", emp, NHibernateUtil.Custom(typeof(EmployeeTypeCustomType)));
int result = final.ExecuteUpdate();
Трассировка стека исключений
<code>
NHibernate.Exceptions.GenericADOException was caught
Message="could not execute native bulk manipulation query:call testCustom (:pLocation)[SQL: SQL not available]"
Source="NHibernate"
SqlString="SQL not available"
StackTrace:
at NHibernate.Engine.Query.NativeSQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.ExecuteNativeUpdate(NativeSQLQuerySpecification nativeQuerySpecification, QueryParameters queryParameters)
at NHibernate.Impl.SqlQueryImpl.ExecuteUpdate()
at TestDatabase.Program.InsertNhibernate() in C:\Jaroori Kachra\TestDatabase\TestDatabase\Program.cs:line 228
InnerException: System.ArgumentOutOfRangeException
Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
Source="mscorlib"
ParamName="index"
StackTrace:
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List<code>1.get_Item(Int32 index)
at NHibernate.Engine.QueryParameters.SetParameterLocation(IList</code>1 sqlParameters, Int32 parameterIndex, Int32 sqlLocation, Int32 span)
at NHibernate.Engine.QueryParameters.PrepareParameterTypes(SqlString sqlString, ISessionFactoryImplementor factory, GetNamedParameterLocations getNamedParameterLocations, Int32 startParameterIndex, Boolean addLimit, Boolean addOffset)
at NHibernate.Engine.Query.NativeSQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session)
InnerException: </p>
<p>
Мой пользовательский класс
public class EmployeeTypeCustomType : ICompositeUserType
{
public Type ReturnedClass { get { return typeof(EmployeeType); } }
public new bool Equals( object x, object y ) {
if ( object.ReferenceEquals(x,y) ) return true;
if (x == null || y == null) return false;
return x.Equals(y);
}
public object DeepCopy(object value) { return value; }
public bool IsMutable { get { return false; } }</p>
<pre><code>public object NullSafeGet(IDataReader dr, string[] names, NHibernate.Engine.ISessionImplementor session, object owner) {
object obj0 = NHibernateUtil.Decimal.NullSafeGet(dr, names[0]);
object obj1 = NHibernateUtil.String.NullSafeGet(dr, names[1]);
if ( obj0==null || obj1==null ) return null;
decimal value = (decimal) obj0;
string currency = (string) obj1;
return new EmployeeType(value, currency);
}
public void NullSafeSet(IDbCommand cmd, object obj, int index, NHibernate.Engine.ISessionImplementor session) {
if (obj == null) {
((IDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
((IDataParameter)cmd.Parameters[index+1]).Value = DBNull.Value;
} else {
EmployeeType amount = (EmployeeType)obj;
((IDataParameter)cmd.Parameters[index]).Value = amount.EmployeeId;
((IDataParameter)cmd.Parameters[index+1]).Value = amount.EmployeeName;
}
}
public string[] PropertyNames {
get { return new string[] { "EmployeeId", "EmployeeName" }; }
}
public NHibernate.Type.IType[] PropertyTypes {
get { return new NHibernate.Type.IType[] {
NHibernateUtil.Decimal, NHibernateUtil.String }; }
}
public object GetPropertyValue(object component, int property) {
EmployeeType amount = (EmployeeType)component;
if (property == 0)
return amount.EmployeeId;
else
return amount.EmployeeName;
}
public void SetPropertyValue(object comp, int property, object value) {
throw new Exception("Immutable!");
}
public object Assemble(object cached,
NHibernate.Engine.ISessionImplementor session, object owner) {
return cached;
}
public object Disassemble(object value,
NHibernate.Engine.ISessionImplementor session) {
return value;
}
Моя хранимая процедура и пользовательский тип в Oracle
<code>
create or replace PROCEDURE testCustom (pLocation IN employeeType) AS
BEGIN
INSERT INTO employee (emp_id, emp_name) values (424746,'test424647');
END; </p>
<p>create or replace TYPE employeeType AS OBJECT (employeeId INT, employeeName VARCHAR2 (50));