Mapping classes with multiple levels of subclass NHibernate

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.

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.

My Mappings

<?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>

When I try to run my program using this mapping I receive this error message, or one similar referring to a different subclass.

*An unhandled exception of type 'NHibernate.Exceptions.GenericADOException' occurred in NHibernate.dll

Additional information: could not insert: [WindowsFormsApplication1.UDP][SQL: INSERT INTO Packets (timeStamp) VALUES (?);SELECT LAST_INSERT_ID()]*

I'm sure this is just down to my lack of understanding of NHibernate and would be very grateful for your help.

Answers


Is your Identity column (ID) actually defined in the database as an auto-increment/identity?

Is your timestamp a database timestamp column? if it is you need access="readonly" because nhibernate is trying to insert into it.

Also, your first joined subclass is missing the or it seems to be in the wrong spot after the last ICMP table.. unless i miss your intent and you want them to be nested.


Need Your Help

OTA deploy with certificate error for iOS8

ios ssl ios8 ota

I have a certificate problem when install app with OTA deployment site in intranet.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.