Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping classes with multiple levels of subclass NHibernate
    primarykey
    data
    text
    <p>I am attempting to map multiple levels of subclass using NHibernate, to which I must admit I am a newbie. The data I am mapping is network packet captures.</p> <p>Basically, I want to be able to split the different levels of inheritance of an object over the tables in my database, so that for example, when I receive a TCP packet the very general data like the timestamp is stored in the 'Packets' table, and the more specific data is stored in its respective table, e.g. the IP header in the 'IP' table and the TCP header in the 'TCP' table.</p> <p>My Mappings</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class name="WindowsFormsApplication1.BasePacket, WindowsFormsApplication1" table="Packets" lazy="false"&gt; &lt;id name="ID" column="ID"&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;property name="timeStamp" column="timeStamp" type="datetime"&gt;&lt;/property&gt; &lt;joined-subclass table="IP" name="WindowsFormsApplication1.IP, WindowsFormsApplication1" lazy="false"&gt; &lt;key column="IPID"/&gt; &lt;property name="identification" column="identification" type="UInt16"&gt;&lt;/property&gt; &lt;property name="sourceIP" column="sourceIP" type="BinaryBlob" &gt;&lt;/property&gt; &lt;property name="destinationIP" column="destinationIP" type="BinaryBlob"&gt;&lt;/property&gt; &lt;property name="version" column="version" type="int"&gt;&lt;/property&gt; &lt;property name="IPHeaderLength" column="IPHeaderLength" type="byte"&gt;&lt;/property&gt; &lt;property name="sizeOfDatagram" column="sizeOfDatagram" type="UInt16"&gt;&lt;/property&gt; &lt;property name="reserved" column="reserved" type="bool"&gt;&lt;/property&gt; &lt;property name="dontFragment" column="dontFragment" type="bool"&gt;&lt;/property&gt; &lt;property name="moreFragments" column="moreFragments" type="bool"&gt;&lt;/property&gt; &lt;property name="fragmentOffset" column="fragmentOffset" type="UInt16"&gt;&lt;/property&gt; &lt;property name="timeToLive" column="timeToLive" type="byte"&gt;&lt;/property&gt; &lt;property name="protocol" column="protocol" type="int"&gt;&lt;/property&gt; &lt;property name="headerChecksum" column="headerChecksum" type="UInt16"&gt;&lt;/property&gt; &lt;property name="additionalData" column="additionalData" type="BinaryBlob"&gt;&lt;/property&gt; &lt;joined-subclass table="TCP" name="WindowsFormsApplication1.TCP, WindowsFormsApplication1" lazy="false"&gt; &lt;key column="TCPID"/&gt; &lt;property name="sourcePort" column="sourcePort" type="UInt16"&gt;&lt;/property&gt; &lt;property name="destinationPort" column="destinationPort" type="UInt16"&gt;&lt;/property&gt; &lt;property name="ISN" column="ISN" type="long"&gt;&lt;/property&gt; &lt;property name="ASN" column="ASN" type="long"&gt;&lt;/property&gt; &lt;property name="innerProtocolHeaderLength" column="innerProtocolHeaderLength" type="byte"&gt;&lt;/property&gt; &lt;property name="FIN" column="FIN" type="bool"&gt;&lt;/property&gt; &lt;property name="SYN" column="SYN" type="bool"&gt;&lt;/property&gt; &lt;property name="RST" column="RST" type="bool"&gt;&lt;/property&gt; &lt;property name="PSH" column="PSH" type="bool"&gt;&lt;/property&gt; &lt;property name="ACK" column="ACK" type="bool"&gt;&lt;/property&gt; &lt;property name="URG" column="URG" type="bool"&gt;&lt;/property&gt; &lt;property name="windowSize" column="windowSize" type="UInt16"&gt;&lt;/property&gt; &lt;property name="checksum" column="checksum" type="UInt16"&gt;&lt;/property&gt; &lt;property name="urgentPointer" column="urgentPointer" type="UInt16"&gt;&lt;/property&gt; &lt;property name="options" column="options" type="BinaryBlob"&gt;&lt;/property&gt; &lt;property name="payload" column="payload" type="BinaryBlob"&gt;&lt;/property&gt; &lt;property name="anomalies" column="anomalies" type="string"&gt;&lt;/property&gt; &lt;/joined-subclass&gt; &lt;joined-subclass table="UDP" name="WindowsFormsApplication1.UDP, WindowsFormsApplication1" lazy="false"&gt; &lt;key column="UDPID"/&gt; &lt;property name="sourcePort" column="sourcePort" type="UInt16"&gt;&lt;/property&gt; &lt;property name="destinationPort" column="destinationPort" type="UInt16"&gt;&lt;/property&gt; &lt;property name="length" column="length" type="UInt16"&gt;&lt;/property&gt; &lt;property name="checksum" column="checksum" type="UInt16"&gt;&lt;/property&gt; &lt;property name="payload" column="payload" type="BinaryBlob"&gt;&lt;/property&gt; &lt;/joined-subclass&gt; &lt;joined-subclass table="ICMP" name="WindowsFormsApplication1.ICMP, WindowsFormsApplication1" lazy="false"&gt; &lt;key column="ICMPID"/&gt; &lt;property name="type" column="type" type="byte"&gt;&lt;/property&gt; &lt;property name="code" column="code" type="byte"&gt;&lt;/property&gt; &lt;property name="checksum" column="checksum" type="UInt16"&gt;&lt;/property&gt; &lt;property name="additionalDataICMP" column="additionalDataICMP" type="BinaryBlob"&gt;&lt;/property&gt; &lt;/joined-subclass&gt; &lt;/joined-subclass&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>When I try to run my program using this mapping I receive this error message, or one similar referring to a different subclass.</p> <p>*An unhandled exception of type 'NHibernate.Exceptions.GenericADOException' occurred in NHibernate.dll</p> <p>Additional information: could not insert: [WindowsFormsApplication1.UDP][SQL: INSERT INTO Packets (timeStamp) VALUES (?);SELECT LAST_INSERT_ID()]*</p> <p>I'm sure this is just down to my lack of understanding of NHibernate and would be very grateful for your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload