我試圖使用NHibernate映射多個級別的子類,我必須承認我是一個新手。我正在映射的數據是網絡數據包捕獲。基本上,我希望能夠在數據庫中的表格上拆分對象的不同繼承級別,例如,當我收到TCP數據包時,像時間戳這樣的一般數據存儲在'數據包'表,更具體的數據存儲在其各自的表中,例如, 'IP'表中的IP頭和'TCP'表中的TCP頭。映射具有多級子類的類NHibernate
我映射
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="WindowsFormsApplication1.BasePacket, WindowsFormsApplication1" table="Packets" lazy="false">
<id name="ID" column="ID">
<generator class="identity" />
</id>
<property name="timeStamp" column="timeStamp" type="datetime"></property>
<joined-subclass table="IP" name="WindowsFormsApplication1.IP, WindowsFormsApplication1" lazy="false">
<key column="IPID"/>
<property name="identification" column="identification" type="UInt16"></property>
<property name="sourceIP" column="sourceIP" type="BinaryBlob" ></property>
<property name="destinationIP" column="destinationIP" type="BinaryBlob"></property>
<property name="version" column="version" type="int"></property>
<property name="IPHeaderLength" column="IPHeaderLength" type="byte"></property>
<property name="sizeOfDatagram" column="sizeOfDatagram" type="UInt16"></property>
<property name="reserved" column="reserved" type="bool"></property>
<property name="dontFragment" column="dontFragment" type="bool"></property>
<property name="moreFragments" column="moreFragments" type="bool"></property>
<property name="fragmentOffset" column="fragmentOffset" type="UInt16"></property>
<property name="timeToLive" column="timeToLive" type="byte"></property>
<property name="protocol" column="protocol" type="int"></property>
<property name="headerChecksum" column="headerChecksum" type="UInt16"></property>
<property name="additionalData" column="additionalData" type="BinaryBlob"></property>
<joined-subclass table="TCP" name="WindowsFormsApplication1.TCP, WindowsFormsApplication1" lazy="false">
<key column="TCPID"/>
<property name="sourcePort" column="sourcePort" type="UInt16"></property>
<property name="destinationPort" column="destinationPort" type="UInt16"></property>
<property name="ISN" column="ISN" type="long"></property>
<property name="ASN" column="ASN" type="long"></property>
<property name="innerProtocolHeaderLength" column="innerProtocolHeaderLength" type="byte"></property>
<property name="FIN" column="FIN" type="bool"></property>
<property name="SYN" column="SYN" type="bool"></property>
<property name="RST" column="RST" type="bool"></property>
<property name="PSH" column="PSH" type="bool"></property>
<property name="ACK" column="ACK" type="bool"></property>
<property name="URG" column="URG" type="bool"></property>
<property name="windowSize" column="windowSize" type="UInt16"></property>
<property name="checksum" column="checksum" type="UInt16"></property>
<property name="urgentPointer" column="urgentPointer" type="UInt16"></property>
<property name="options" column="options" type="BinaryBlob"></property>
<property name="payload" column="payload" type="BinaryBlob"></property>
<property name="anomalies" column="anomalies" type="string"></property>
</joined-subclass>
<joined-subclass table="UDP" name="WindowsFormsApplication1.UDP, WindowsFormsApplication1" lazy="false">
<key column="UDPID"/>
<property name="sourcePort" column="sourcePort" type="UInt16"></property>
<property name="destinationPort" column="destinationPort" type="UInt16"></property>
<property name="length" column="length" type="UInt16"></property>
<property name="checksum" column="checksum" type="UInt16"></property>
<property name="payload" column="payload" type="BinaryBlob"></property>
</joined-subclass>
<joined-subclass table="ICMP" name="WindowsFormsApplication1.ICMP, WindowsFormsApplication1" lazy="false">
<key column="ICMPID"/>
<property name="type" column="type" type="byte"></property>
<property name="code" column="code" type="byte"></property>
<property name="checksum" column="checksum" type="UInt16"></property>
<property name="additionalDataICMP" column="additionalDataICMP" type="BinaryBlob"></property>
</joined-subclass>
</joined-subclass>
</class>
</hibernate-mapping>
當我嘗試使用這個映射我收到此錯誤信息,或一個類似指的是不同的子類來運行我的程序。
*型 'NHibernate.Exceptions.GenericADOException' 未處理的異常發生在NHibernate.dll
其他信息:無法插入:[WindowsFormsApplication1.UDP] [SQL:INSERT INTO包(時間戳)VALUES(? ); SELECT LAST_INSERT_ID()] *
我確信這只是我對NHibernate的理解不夠,並且非常感謝您的幫助。
顯示完整的堆棧跟蹤。這很可能是映射錯誤,數據庫抱怨某些列未知 – Firo