Hi I m trying to pass User Defined Type as parameter to stored
procedure define in Oracle.Its is working fine with Oracle 11 +
ADO.net.But facing problem in integrating with NHibernate.

Following are the IType implementation procedure ,User defined Type ,
Call from NHibernate and Exception coming.
  public class EmployeeCustomTest: NHibernate.Type.IType
    {
        private static readonly SqlType[] sqlTypes = new SqlType[]
{new SqlType(DbType.Object)};

       // private static readonly SqlType[] sqlTypes = new SqlType[]
{ new SqlType(DbType.Object) };
        #region IType Members
        public void NullSafeSet(IDbCommand cmd, object value, int
index, ISessionImplementor session)
        {
            if (value == null)
            {
                ((IDataParameter)cmd.Parameters[index]).Value =
DBNull.Value;
                ((IDataParameter)cmd.Parameters[index + 1]).Value =
DBNull.Value;
            }
            else
            {
                var name = (EmployeeType)value;
                ((IDataParameter)cmd.Parameters[index]).Value = name;
                //((IDataParameter)cmd.Parameters[index]).Value =
(object)name.EmployeeId ?? DBNull.Value;
                //((IDataParameter)cmd.Parameters[index + 1]).Value =
(object)name.EmployeeName ?? DBNull.Value;
            }
        }

        public SqlType[] SqlTypes(NHibernate.Engine.IMapping mapping)
        {
            return sqlTypes;
        }
        public IType[] PropertyTypes
        {
            get { return new IType[] { NHibernateUtil.Int32,
NHibernateUtil.String }; }
        }
        public bool IsCollectionType
        {
            get { return true; }
        }
        public int GetColumnSpan(NHibernate.Engine.IMapping mapping)
        {
            return 1;
        }

        public int Compare(object x, object y, EntityMode? entityMode)
        {
            throw new NotImplementedException();
        }

        public object DeepCopy(object val, EntityMode entityMode,
NHibernate.Engine.ISessionFactoryImplementor factory)
        {
            throw new NotImplementedException();
        }

        public object FromXMLNode(System.Xml.XmlNode xml,
NHibernate.Engine.IMapping factory)
        {
            throw new NotImplementedException();
        }

        public int GetHashCode(object x, EntityMode entityMode,
NHibernate.Engine.ISessionFactoryImplementor factory)
        {
            throw new NotImplementedException();
        }

        public int GetHashCode(object x, EntityMode entityMode)
        {
            throw new NotImplementedException();
        }

        public IType
GetSemiResolvedType(NHibernate.Engine.ISessionFactoryImplementor
factory)
        {
            throw new NotImplementedException();
        }

        public object Hydrate(IDataReader rs, string[] names,
NHibernate.Engine.ISessionImplementor session, object owner)
        {
            throw new NotImplementedException();
        }

        public bool IsAnyType
        {
            get { throw new NotImplementedException(); }
        }

        public bool IsAssociationType
        {
            get { throw new NotImplementedException(); }
        }

        public bool IsComponentType
        {
            get { throw new NotImplementedException(); }
        }

        public bool IsDirty(object old, object current, bool[]
checkable, NHibernate.Engine.ISessionImplementor session)
        {
            throw new NotImplementedException();
        }

        public bool IsDirty(object old, object current,
NHibernate.Engine.ISessionImplementor session)
        {
            throw new NotImplementedException();
        }

        public bool IsEntityType
        {
            get { throw new NotImplementedException(); }
        }

        public bool IsEqual(object x, object y, EntityMode entityMode,
NHibernate.Engine.ISessionFactoryImplementor factory)
        {
            throw new NotImplementedException();
        }

        public bool IsEqual(object x, object y, EntityMode entityMode)
        {
            throw new NotImplementedException();
        }

        public bool IsModified(object oldHydratedState, object
currentState, bool[] checkable, NHibernate.Engine.ISessionImplementor
session)
        {
            throw new NotImplementedException();
        }

        public bool IsMutable
        {
            get { throw new NotImplementedException(); }
        }

        public bool IsSame(object x, object y, EntityMode entityMode)
        {
            throw new NotImplementedException();
        }

        public bool IsXMLElement
        {
            get { throw new NotImplementedException(); }
        }

        public string Name
        {
            get { throw new NotImplementedException(); }
        }

        public object NullSafeGet(IDataReader dr, string[] names,
ISessionImplementor session, object owner)
        {
            var employeeId = NHibernateUtil.String.NullSafeGet(dr,
names[0]);
            var employeeName = NHibernateUtil.String.NullSafeGet(dr,
names[1]);
            return new EmployeeType
            {
                EmployeeId = (int)employeeId,
                EmployeeName = employeeName.ToString()
            };
        }


        public void NullSafeSet(IDbCommand st, object value, int
index, bool[] settable, NHibernate.Engine.ISessionImplementor session)
        {
            throw new NotImplementedException();
        }

        public object Replace(object original, object target,
NHibernate.Engine.ISessionImplementor session, object owner,
System.Collections.IDictionary copyCache, ForeignKeyDirection
foreignKeyDirection)
        {
            throw new NotImplementedException();
        }

        public object Replace(object original, object target,
NHibernate.Engine.ISessionImplementor session, object owner,
System.Collections.IDictionary copiedAlready)
        {
            throw new NotImplementedException();
        }

        public object ResolveIdentifier(object value,
NHibernate.Engine.ISessionImplementor session, object owner)
        {
            throw new NotImplementedException();
        }

        public Type ReturnedClass
        {
            get { return typeof(EmployeeType); }
        }

        public object SemiResolve(object value,
NHibernate.Engine.ISessionImplementor session, object owner)
        {
            throw new NotImplementedException();
        }

        public void SetToXMLNode(System.Xml.XmlNode node, object
value, NHibernate.Engine.ISessionFactoryImplementor factory)
        {
            throw new NotImplementedException();
        }

        public bool[] ToColumnNullness(object value,
NHibernate.Engine.IMapping mapping)
        {
            throw new NotImplementedException();
        }

        public string ToLoggableString(object value,
NHibernate.Engine.ISessionFactoryImplementor factory)
        {
            throw new NotImplementedException();
        }

        public object GetPropertyValue(object component, int property)
        {
            var name = (EmployeeType)component;
            if (property == 0)
                return name.EmployeeId;
            else
                return name.EmployeeName;
        }

        public object NullSafeGet(IDataReader rs, string name,
ISessionImplementor session, object owner)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ICacheAssembler Members

        public object Assemble(object cached,
NHibernate.Engine.ISessionImplementor session, object owner)
        {
            throw new NotImplementedException();
        }

        public void BeforeAssemble(object cached,
NHibernate.Engine.ISessionImplementor session)
        {
            throw new NotImplementedException();
        }

        public object Disassemble(object value,
NHibernate.Engine.ISessionImplementor session, object owner)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

<pre><code>
**********************Procedure***********************************
PROCEDURE "TESTCUSTOMEMPLOYEE" ("PARAM" IN "EMPLOYEECUSTOMTEST",
 "PARAM1" OUT SYS_REFCURSOR) IS
BEGIN
 open PARAM1 for select * from employee;
END;</pre></code>

<pre><code>
**********************User Defined Type In
Oracle11g***********************************
Create or Replace TYPE "EMPLOYEECUSTOMTEST" AS OBJECT
(
  "EMPLOYEEID" NUMBER(38,90),
  "EMPLOYEENAME" VARCHAR2(200),
)
</pre></code>

<pre><code>
************************Call from
NHibernate*************************************
  EmployeeType EMPCUST = new EmployeeType();
  EMPCUST.EmployeeId = 255060;
  EMPCUST.EmployeeName = "PALLAVI";
  ISQLQuery final = eventhistorysession.CreateSQLQuery("CALL
TESTCUSTOMEMPLOYEE param = :id");
  final.SetParameter("id", EMPCUST,new EMPLOYEECUSTOMTEST());
  IList result = final.List();
  tx.Commit();
</pre></code>

<pre><code>
**************************Exception***************************************
 InnerException: System.ArgumentException
       Message="Invalid parameter binding\r\nParameter name: :p0"
       Source="Oracle.DataAccess"
       ParamName=":p0"
       StackTrace:
</pre></code>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhusers@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to