Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Discriminated Subclasses of a Joined-Subclass

Here's my heirarchy:

class abstract Entity { /*members*/ } // mapped to entity table
class abstract User : Entity { /*members*/ } // mapped to user table

class Employee : User { /*no members*/ } // no table, discriminator = "E"
class Contractor : User { /*no members*/ } // no table, discriminator = "C"

Here's my mappings in two separate hbm files:

<class name="Entity" table="entity" xmlns="urn:nhibernate-mapping-2.2">
  <id name="Id" column="id">
    <generator class="guid.comb" />
  </id>
  <property ... />
</class>

<joined-subclass name="User" extends="Entity" table="user">
  <key column="id" />
  <discriminator column="type" />
  <property ... />
  <subclass name="Employee"   discriminator-value="E" />
  <subclass name="Contractor" discriminator-value="C" />
</joined-subclass>

The following is the exception I get:

MappingException: XML validation error: The element 'joined-subclass' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'discriminator' in namespace 'urn:nhibernate-mapping-2.2'.

What am I missing? Can you not map a discriminated subclass hierarchy of a joined-subclass?

like image 448
Travis Heseman Avatar asked Jan 24 '11 17:01

Travis Heseman


1 Answers

What you want to do is not currently possible.

Check http://www.nhforge.org/doc/nh/en/index.html#inheritance for allowed constructs.

like image 109
Diego Mijelshon Avatar answered Oct 09 '22 11:10

Diego Mijelshon