2011-07-01 3 views
0

XmlElement 타입의 프라퍼티를 가지고 있습니다. 속성은 다음과 같이 매핑된다 :Hibernate는 XMLType과 관련된 문제점을

<property name="XamlForm" column="XamlForm" type="KTN.Base.Data.Types.XmlType, KTN.Base.Data" /> 

XMLTYPE 클래스 :

[Serializable] 
public class XmlType : IUserType 
{ 
    public new bool Equals(object x, object y) 
    { 
     XmlElement xdoc_x = (XmlElement)x; 
     XmlElement xdoc_y = (XmlElement)y; 

     if (xdoc_x == null && xdoc_y == null) return true; 

     if (xdoc_x == null || xdoc_y == null) return false; 

     return xdoc_y.OuterXml == xdoc_x.OuterXml; 
    } 

    public object NullSafeGet(IDataReader rs, string[] names, object owner) 
    { 
     if (names.Length != 1) 
      throw new InvalidOperationException("names array has more than one element. can't handle this!"); 
     XmlDocument document = new XmlDocument(); 
     string val = rs[names[0]] as string; 
     if (val != null) 
     { 
      document.LoadXml(val); 

      return document.DocumentElement; 
     } 
     return null; 
    } 

    public void NullSafeSet(IDbCommand cmd, object value, int index) 
    { 
     DbParameter parameter = (DbParameter)cmd.Parameters[index]; 
     if (value == null) 
     { 
      parameter.Value = DBNull.Value; 
      return; 
     } 
     parameter.Value = ((XmlElement)value).OuterXml; 
    } 

    public object DeepCopy(object value) 
    { 
     if (value == null) return null; 
     XmlElement other = (XmlElement)value; 
     XmlDocument xdoc = new XmlDocument(); 
     xdoc.LoadXml(other.OuterXml); 
     return xdoc.DocumentElement; /**/ 
    } 

    public SqlType[] SqlTypes 
    { 
     get 
     { 
      return new SqlType[] { new SqlXmlType() }; 
     } 
    } 

    public System.Type ReturnedType 
    { 
     get { return typeof(XmlDocument); } 
    } 

    public bool IsMutable 
    { 
     get { return true; } 
    } 

    public object Assemble(object cached, object owner) 
    { 
     return cached; 
    } 

    public object Disassemble(object value) 
    { 
     return value; 
    } 

    public int GetHashCode(object x) 
    { 
     return x.GetHashCode(); 
    } 

    public object Replace(object original, object target, object owner) 
    { 
     // Changed return original to return target... 
     return target; 
    } 

} 

후 함수 NHibernate에 병합로부터 호출이 속성은 널이다. 아이디어가 있으십니까? 미리 감사드립니다.

+0

아마도 당신은 Equals fn에서 null 체크를 원할 것입니다. – leeny

답변

0

NHibernate 3은 XDocumentXmlDocument의 두 가지 종류의 기본형을 모두 제공합니다.

자신을 굴릴 필요가 없습니다.

관련 문제